Tests: use errors dump instead of ALLOW_UNRESOLVED_REFERENCE
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
// ERROR: Unresolved reference: s
|
||||||
|
// ERROR: Unresolved reference: s
|
||||||
|
// ERROR: Unresolved reference: s
|
||||||
|
// ERROR: Unresolved reference: s
|
||||||
fun foo() {
|
fun foo() {
|
||||||
s.extensionFun()
|
s.extensionFun()
|
||||||
for (i in s.indices) {
|
for (i in s.indices) {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// RUNTIME
|
// RUNTIME
|
||||||
// ALLOW_UNRESOLVED
|
|
||||||
|
|
||||||
fun foo(s: String) {
|
fun foo(s: String) {
|
||||||
<selection> s.extensionFun()
|
<selection> s.extensionFun()
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: Type mismatch: inferred type is kotlin.Unit but a.A was expected
|
||||||
package to
|
package to
|
||||||
|
|
||||||
import a.*
|
import a.*
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// ERROR: Unresolved reference: c
|
||||||
|
// ERROR: Unresolved reference: d
|
||||||
|
// ERROR: Unresolved reference: g
|
||||||
|
// ERROR: Unresolved reference: j
|
||||||
package to
|
package to
|
||||||
|
|
||||||
fun f() = c + d + g + j()
|
fun f() = c + d + g + j()
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package a
|
package a
|
||||||
|
|
||||||
// ALLOW_UNRESOLVED
|
|
||||||
|
|
||||||
class A(val c: Int = 1) {
|
class A(val c: Int = 1) {
|
||||||
var d = 2
|
var d = 2
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: A 'return' expression required in a function with a block body ('{...}')
|
||||||
package to
|
package to
|
||||||
|
|
||||||
import a.A
|
import a.A
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: Unresolved reference: f
|
||||||
package to
|
package to
|
||||||
|
|
||||||
fun g() {
|
fun g() {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package a
|
package a
|
||||||
|
|
||||||
// ALLOW_UNRESOLVED
|
|
||||||
//NOTE: is is an unsupported case
|
//NOTE: is is an unsupported case
|
||||||
class A {
|
class A {
|
||||||
<selection>fun g() {
|
<selection>fun g() {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package a
|
package a
|
||||||
|
|
||||||
// ALLOW_UNRESOLVED
|
|
||||||
|
|
||||||
class C {
|
class C {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: Unresolved reference: A
|
||||||
package to
|
package to
|
||||||
|
|
||||||
val c = A()
|
val c = A()
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
// ALLOW_UNRESOLVED
|
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// NO_ERRORS_DUMP
|
||||||
package a
|
package a
|
||||||
|
|
||||||
trait T
|
trait T
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: Type mismatch: inferred type is kotlin.Unit but d.A was expected
|
||||||
package to
|
package to
|
||||||
|
|
||||||
import d.A
|
import d.A
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// ERROR: Overload resolution ambiguity: internal fun a.A.ext(): kotlin.Unit defined in a internal fun a.A.ext(): kotlin.Unit defined in to
|
||||||
|
// ERROR: Overload resolution ambiguity: internal var a.A.p: kotlin.Int defined in a internal var a.A.p: kotlin.Int defined in to
|
||||||
|
// ERROR: Overload resolution ambiguity: internal var a.A.p: kotlin.Int defined in a internal var a.A.p: kotlin.Int defined in to
|
||||||
package to
|
package to
|
||||||
|
|
||||||
import a.A
|
import a.A
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
// ERROR: Overload resolution ambiguity: internal fun a.A.ext(): kotlin.Unit defined in a internal fun a.A.ext(): kotlin.Unit defined in to
|
||||||
|
// ERROR: Overload resolution ambiguity: internal fun a.A.plus(a: a.A): kotlin.Unit defined in a internal fun a.A.plus(a: a.A): kotlin.Unit defined in to
|
||||||
|
// ERROR: Overload resolution ambiguity: internal fun a.A.infix(a: a.A): kotlin.Unit defined in a internal fun a.A.infix(a: a.A): kotlin.Unit defined in to
|
||||||
|
// ERROR: Overload resolution ambiguity: internal fun a.A.minus(): kotlin.Unit defined in a internal fun a.A.minus(): kotlin.Unit defined in to
|
||||||
|
// ERROR: Overload resolution ambiguity: internal val a.A.p: kotlin.Int defined in a internal val a.A.p: kotlin.Int defined in to
|
||||||
package to
|
package to
|
||||||
|
|
||||||
import a.A
|
import a.A
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// ERROR: Unresolved reference: T
|
||||||
|
// ERROR: Unresolved reference: b
|
||||||
|
// ERROR: Unresolved reference: c
|
||||||
package to
|
package to
|
||||||
|
|
||||||
fun f() {
|
fun f() {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//RUNTIME
|
//RUNTIME
|
||||||
// ALLOW_UNRESOLVED
|
|
||||||
|
|
||||||
package a
|
package a
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: Type mismatch: inferred type is kotlin.Unit but d.A was expected
|
||||||
package to
|
package to
|
||||||
|
|
||||||
import d.A
|
import d.A
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
package to
|
|
||||||
|
|
||||||
package a
|
package a
|
||||||
|
|
||||||
import a.A
|
import a.A
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// ALLOW_UNRESOLVED
|
// NO_ERRORS_DUMP
|
||||||
|
|
||||||
<selection>package a
|
<selection>package a
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1 @@
|
|||||||
package to
|
|
||||||
|
|
||||||
<caret>
|
<caret>
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: Nested class 'Nested' should be qualified as 'A.Nested'
|
||||||
package to
|
package to
|
||||||
|
|
||||||
import a.ext
|
import a.ext
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
// ERROR: Unresolved reference: Inner
|
||||||
|
// ERROR: Unresolved reference: Nested
|
||||||
|
// ERROR: Unresolved reference: NestedEnum
|
||||||
|
// ERROR: Unresolved reference: NestedObj
|
||||||
|
// ERROR: Unresolved reference: NestedTrait
|
||||||
|
// ERROR: Unresolved reference: NestedAnnotation
|
||||||
package to
|
package to
|
||||||
|
|
||||||
class Outer {
|
class Outer {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package a
|
package a
|
||||||
|
|
||||||
// ALLOW_UNRESOLVED
|
|
||||||
//NOTE: This test shows a corner case which is not covered fully by current implementation
|
//NOTE: This test shows a corner case which is not covered fully by current implementation
|
||||||
// All we do now is avoid inserting wrong imports (we do not import anything for declaration from copied block)
|
// All we do now is avoid inserting wrong imports (we do not import anything for declaration from copied block)
|
||||||
// To cover this case properly and insert good imports some other approach should be used (some sophisticated heuristic might do the job)
|
// To cover this case properly and insert good imports some other approach should be used (some sophisticated heuristic might do the job)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package a;
|
package a;
|
||||||
|
|
||||||
class JavaM {
|
public class JavaM {
|
||||||
static void staticMethod() {
|
public static void staticMethod() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JavaF {
|
public class JavaF {
|
||||||
static int staticField = 0;
|
public static int staticField = 0;
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: Expression 'staticField' of type 'kotlin.Int' cannot be invoked as a function. The function invoke() is not found
|
||||||
package to
|
package to
|
||||||
|
|
||||||
import a.JavaF
|
import a.JavaF
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// ERROR: Unresolved reference: A
|
||||||
|
// ERROR: Unresolved reference: g
|
||||||
package to
|
package to
|
||||||
|
|
||||||
fun f() {
|
fun f() {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package a
|
package a
|
||||||
|
|
||||||
// ALLOW_UNRESOLVED
|
|
||||||
|
|
||||||
fun f() {
|
fun f() {
|
||||||
fun g(): Int {
|
fun g(): Int {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// ERROR: Cannot access 'd': it is 'private' in 'a'
|
||||||
|
// ERROR: Cannot access 'd': it is 'private' in 'a'
|
||||||
|
// ERROR: Cannot access 'b': it is 'private' in 'a'
|
||||||
|
// ERROR: Cannot access 'b': it is 'private' in 'a'
|
||||||
package to
|
package to
|
||||||
|
|
||||||
import a.b
|
import a.b
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: No value passed for parameter i
|
||||||
package a
|
package a
|
||||||
|
|
||||||
fun f(p: A, t: T) {
|
fun f(p: A, t: T) {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// ERROR: Type mismatch: inferred type is kotlin.Unit but to.A was expected
|
||||||
|
// ERROR: Function 'ext' must have a body
|
||||||
package to
|
package to
|
||||||
|
|
||||||
trait T
|
trait T
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: No supertypes are accessible in this context
|
||||||
package to
|
package to
|
||||||
|
|
||||||
fun f() {
|
fun f() {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ERROR: Function 'f' must have a body
|
||||||
package to
|
package to
|
||||||
|
|
||||||
import a.A
|
import a.A
|
||||||
|
|||||||
+9
-48
@@ -18,26 +18,18 @@ package org.jetbrains.kotlin.idea.codeInsight
|
|||||||
|
|
||||||
import com.intellij.openapi.actionSystem.IdeActions
|
import com.intellij.openapi.actionSystem.IdeActions
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import org.jetbrains.kotlin.checkers.DebugInfoUtil
|
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
|
||||||
import org.jetbrains.kotlin.idea.AbstractCopyPasteTest
|
import org.jetbrains.kotlin.idea.AbstractCopyPasteTest
|
||||||
import org.jetbrains.kotlin.idea.PluginTestCaseBase
|
import org.jetbrains.kotlin.idea.PluginTestCaseBase
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.testUtils.dumpTextWithErrors
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
|
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
import org.jetbrains.kotlin.psi.JetReferenceExpression
|
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import org.jetbrains.kotlin.test.JetTestUtils
|
import org.jetbrains.kotlin.test.JetTestUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.test.fail
|
|
||||||
|
|
||||||
public abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest() {
|
public abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest() {
|
||||||
private val BASE_PATH = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/imports"
|
private val BASE_PATH = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/imports"
|
||||||
private val DEFAULT_TO_FILE_TEXT = "package to\n\n<caret>"
|
private val DEFAULT_TO_FILE_TEXT = "package to\n\n<caret>"
|
||||||
private val ALLOW_UNRESOLVED_DIRECTIVE = "// ALLOW_UNRESOLVED"
|
private val NO_ERRORS_DUMP_DIRECTIVE = "// NO_ERRORS_DUMP"
|
||||||
|
|
||||||
override fun getTestDataPath() = BASE_PATH
|
override fun getTestDataPath() = BASE_PATH
|
||||||
|
|
||||||
@@ -61,18 +53,18 @@ public abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest()
|
|||||||
|
|
||||||
KotlinCopyPasteReferenceProcessor.declarationsToImportSuggested = emptyList()
|
KotlinCopyPasteReferenceProcessor.declarationsToImportSuggested = emptyList()
|
||||||
|
|
||||||
val toFileName = testFileName.replace(".kt", ".to.kt")
|
configureToFile(testFileName.replace(".kt", ".to.kt"))
|
||||||
val toFile = configureToFile(toFileName)
|
|
||||||
performNotWriteEditorAction(IdeActions.ACTION_PASTE)
|
performNotWriteEditorAction(IdeActions.ACTION_PASTE)
|
||||||
|
|
||||||
val namesToImportDump = KotlinCopyPasteReferenceProcessor.declarationsToImportSuggested.joinToString("\n")
|
val namesToImportDump = KotlinCopyPasteReferenceProcessor.declarationsToImportSuggested.joinToString("\n")
|
||||||
JetTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.names")), namesToImportDump)
|
JetTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.names")), namesToImportDump)
|
||||||
|
|
||||||
JetTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.kt")), myFixture.getEditor().getDocument().getText())
|
val resultFile = myFixture.getFile() as JetFile
|
||||||
|
val resultText = if (InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(testFile, true), NO_ERRORS_DUMP_DIRECTIVE))
|
||||||
if (!InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(testFile, true), ALLOW_UNRESOLVED_DIRECTIVE)) {
|
resultFile.getText()
|
||||||
checkNoUnresolvedReferences(toFile)
|
else
|
||||||
}
|
resultFile.dumpTextWithErrors()
|
||||||
|
JetTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.kt")), resultText)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureToFile(toFileName: String): JetFile {
|
private fun configureToFile(toFileName: String): JetFile {
|
||||||
@@ -96,35 +88,4 @@ public abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkNoUnresolvedReferences(file: JetFile) {
|
|
||||||
val bindingContext = file.analyzeFully()
|
|
||||||
for (diagnostic in bindingContext.getDiagnostics()) {
|
|
||||||
if (Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS.contains(diagnostic.getFactory())) {
|
|
||||||
val textRanges = diagnostic.getTextRanges()
|
|
||||||
val diagnosticText = DefaultErrorMessages.render(diagnostic)
|
|
||||||
if (diagnostic.getPsiFile() == file) {
|
|
||||||
fail(diagnostic.getFactory().getName() + ": " + diagnosticText + " " + DiagnosticUtils.atLocation(file, textRanges.get(0)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DebugInfoUtil.markDebugAnnotations(file, bindingContext, object : DebugInfoUtil.DebugInfoReporter() {
|
|
||||||
override fun preProcessReference(expression: JetReferenceExpression) {
|
|
||||||
expression.analyze(BodyResolveMode.FULL)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun reportElementWithErrorType(expression: JetReferenceExpression) {
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun reportMissingUnresolved(expression: JetReferenceExpression) {
|
|
||||||
// this may happen if incorrect psi transformations are done
|
|
||||||
fail(expression.getText() + " is unresolved but not marked " + DiagnosticUtils.atLocation(file, expression.getTextRange()))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun reportUnresolvedWithTarget(expression: JetReferenceExpression, target: String) {
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,12 @@ import com.intellij.openapi.roots.ModifiableRootModel
|
|||||||
import com.intellij.openapi.roots.ModuleRootModificationUtil.updateModel
|
import com.intellij.openapi.roots.ModuleRootModificationUtil.updateModel
|
||||||
import com.intellij.testFramework.LightProjectDescriptor
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
import com.intellij.util.Consumer
|
import com.intellij.util.Consumer
|
||||||
|
import org.jetbrains.kotlin.diagnostics.Severity
|
||||||
|
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||||
import org.jetbrains.kotlin.idea.JetStdJSProjectDescriptor
|
import org.jetbrains.kotlin.idea.JetStdJSProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.ProjectDescriptorWithStdlibSources
|
import org.jetbrains.kotlin.idea.ProjectDescriptorWithStdlibSources
|
||||||
|
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
|
||||||
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
|
|
||||||
public enum class ModuleKind {
|
public enum class ModuleKind {
|
||||||
KOTLIN_JVM_WITH_STDLIB_SOURCES
|
KOTLIN_JVM_WITH_STDLIB_SOURCES
|
||||||
@@ -53,3 +57,11 @@ public fun Module.configureAs(kind: ModuleKind) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun JetFile.dumpTextWithErrors(): String {
|
||||||
|
val diagnostics = analyzeFullyAndGetResult().bindingContext.getDiagnostics()
|
||||||
|
val errors = diagnostics.filter { it.getSeverity() == Severity.ERROR }
|
||||||
|
if (errors.isEmpty()) return getText()
|
||||||
|
val header = errors.map { "// ERROR: " + DefaultErrorMessages.render(it).replace('\n', ' ') }.joinToString("\n", postfix = "\n")
|
||||||
|
return header + getText()
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import com.intellij.testFramework.LightPlatformTestCase
|
|||||||
import org.jetbrains.kotlin.idea.JetWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.JetWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.j2k.IdeaResolverForConverter
|
import org.jetbrains.kotlin.idea.j2k.IdeaResolverForConverter
|
||||||
import org.jetbrains.kotlin.idea.j2k.J2kPostProcessor
|
import org.jetbrains.kotlin.idea.j2k.J2kPostProcessor
|
||||||
|
import org.jetbrains.kotlin.idea.testUtils.dumpTextWithErrors
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
@@ -71,13 +72,13 @@ public abstract class AbstractJavaToKotlinConverterMultiFileTest : AbstractJavaT
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ((i, kotlinFile) in resultFiles.withIndex()) {
|
for ((i, kotlinFile) in resultFiles.withIndex()) {
|
||||||
JetTestUtils.assertEqualsToFile(expectedResultFile(i), addErrorsDump(kotlinFile))
|
JetTestUtils.assertEqualsToFile(expectedResultFile(i), kotlinFile.dumpTextWithErrors())
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((externalFile, externalPsiFile) in externalFiles.zip(externalPsiFiles)) {
|
for ((externalFile, externalPsiFile) in externalFiles.zip(externalPsiFiles)) {
|
||||||
val expectedFile = File(externalFile.getPath() + ".expected")
|
val expectedFile = File(externalFile.getPath() + ".expected")
|
||||||
var resultText = if (externalPsiFile is JetFile) {
|
var resultText = if (externalPsiFile is JetFile) {
|
||||||
addErrorsDump(externalPsiFile)
|
externalPsiFile.dumpTextWithErrors()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//TODO: errors dump for java files too
|
//TODO: errors dump for java files too
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.idea.JetWithJdkAndRuntimeLightProjectDescriptor
|
|||||||
import com.intellij.psi.PsiJavaFile
|
import com.intellij.psi.PsiJavaFile
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
import org.jetbrains.kotlin.idea.j2k.IdeaResolverForConverter
|
import org.jetbrains.kotlin.idea.j2k.IdeaResolverForConverter
|
||||||
|
import org.jetbrains.kotlin.idea.testUtils.dumpTextWithErrors
|
||||||
|
|
||||||
public abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJavaToKotlinConverterTest() {
|
public abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJavaToKotlinConverterTest() {
|
||||||
val testHeaderPattern = Pattern.compile("//(element|expression|statement|method|class|file|comp)\n")
|
val testHeaderPattern = Pattern.compile("//(element|expression|statement|method|class|file|comp)\n")
|
||||||
@@ -80,7 +81,7 @@ public abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJava
|
|||||||
var actual = reformat(rawConverted, project, reformatInFun)
|
var actual = reformat(rawConverted, project, reformatInFun)
|
||||||
|
|
||||||
if (prefix == "file") {
|
if (prefix == "file") {
|
||||||
actual = addErrorsDump(createKotlinFile(actual))
|
actual = createKotlinFile(actual).dumpTextWithErrors()
|
||||||
}
|
}
|
||||||
|
|
||||||
val kotlinPath = javaPath.replace(".java", ".kt")
|
val kotlinPath = javaPath.replace(".java", ".kt")
|
||||||
|
|||||||
@@ -67,13 +67,5 @@ public abstract class AbstractJavaToKotlinConverterTest : LightCodeInsightFixtur
|
|||||||
protected fun deleteFile(virtualFile: VirtualFile) {
|
protected fun deleteFile(virtualFile: VirtualFile) {
|
||||||
runWriteAction { virtualFile.delete(this) }
|
runWriteAction { virtualFile.delete(this) }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun addErrorsDump(jetFile: JetFile): String {
|
|
||||||
val diagnostics = jetFile.analyzeFullyAndGetResult().bindingContext.getDiagnostics()
|
|
||||||
val errors = diagnostics.filter { it.getSeverity() == Severity.ERROR }
|
|
||||||
if (errors.isEmpty()) return jetFile.getText()
|
|
||||||
val header = errors.map { "// ERROR: " + DefaultErrorMessages.render(it).replace('\n', ' ') }.joinToString("\n", postfix = "\n")
|
|
||||||
return header + jetFile.getText()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user