From 0e42de4e99441a6363a8d4307e275fe9e0f39cd1 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 17 Oct 2014 16:48:36 +0400 Subject: [PATCH] CHECK_TYPES injected through imports --- .../testData/diagnostics/tests/checkType.txt | 8 -- .../functionLIteralInBlockInIf.txt | 8 -- .../functionLiteralWithoutArgumentList.txt | 8 -- .../setterNotProjectedOutAssign.txt | 10 +-- .../setterProjectedOutAssign.txt | 10 +-- .../equalityConstraintOnNullableType.txt | 8 -- .../notNullConstraintOnNullableType.txt | 8 -- .../subtypeConstraintOnNullableType.txt | 8 -- .../supertypeConstraintOnNullableType.txt | 8 -- .../numbers/numbersInSimpleConstraints.txt | 10 +-- .../commonSupertype/mixedElvis.txt | 8 -- .../platformTypes/commonSupertype/mixedIf.txt | 8 -- .../commonSupertype/withNothing.txt | 8 -- .../explicitFlexibleNoPackage.txt | 8 -- .../explicitFlexibleWithPackage.txt | 8 -- .../tests/platformTypes/safeCall.txt | 8 -- .../jet/checkers/BaseDiagnosticsTest.java | 87 ++++++++++++------- 17 files changed, 59 insertions(+), 162 deletions(-) diff --git a/compiler/testData/diagnostics/tests/checkType.txt b/compiler/testData/diagnostics/tests/checkType.txt index b0ec567743a..c06fb64d219 100644 --- a/compiler/testData/diagnostics/tests/checkType.txt +++ b/compiler/testData/diagnostics/tests/checkType.txt @@ -1,7 +1,6 @@ package internal fun test(/*0*/ b: B): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit internal trait A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -20,10 +19,3 @@ internal trait C : B { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/functionLIteralInBlockInIf.txt b/compiler/testData/diagnostics/tests/functionLiterals/functionLIteralInBlockInIf.txt index cfdc71b1087..b8def46715c 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/functionLIteralInBlockInIf.txt +++ b/compiler/testData/diagnostics/tests/functionLiterals/functionLIteralInBlockInIf.txt @@ -1,11 +1,3 @@ package internal fun test(): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.txt b/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.txt index 7d3d734dd9b..88cf5399041 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.txt +++ b/compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.txt @@ -2,11 +2,3 @@ package internal fun foo(): kotlin.Unit internal fun id(/*0*/ t: T): T -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/generics/varProjection/setterNotProjectedOutAssign.txt b/compiler/testData/diagnostics/tests/generics/varProjection/setterNotProjectedOutAssign.txt index 2293e513899..723e8b37e0d 100644 --- a/compiler/testData/diagnostics/tests/generics/varProjection/setterNotProjectedOutAssign.txt +++ b/compiler/testData/diagnostics/tests/generics/varProjection/setterNotProjectedOutAssign.txt @@ -1,18 +1,10 @@ package internal fun test(/*0*/ t: Tr): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit internal trait Tr { internal abstract var v: Tr public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.txt b/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.txt index 57240dff538..f97c0ab06f4 100644 --- a/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.txt +++ b/compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.txt @@ -1,18 +1,10 @@ package internal fun test(/*0*/ t: Tr): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit internal trait Tr { internal abstract var v: T public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/equalityConstraintOnNullableType.txt b/compiler/testData/diagnostics/tests/inference/constraints/equalityConstraintOnNullableType.txt index a3d3098e2f9..3903eac7379 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/equalityConstraintOnNullableType.txt +++ b/compiler/testData/diagnostics/tests/inference/constraints/equalityConstraintOnNullableType.txt @@ -3,17 +3,9 @@ package internal fun doA(/*0*/ a: A): T internal fun foo(/*0*/ a: A, /*1*/ aN: A): T internal fun test(/*0*/ a: A, /*1*/ aN: A): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit internal trait A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.txt b/compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.txt index 8d032f97867..1e64fea6d44 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.txt +++ b/compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.txt @@ -5,7 +5,6 @@ internal fun doIn(/*0*/ i: In): kotlin.Unit internal fun doOut(/*0*/ o: Out): T internal fun doT(/*0*/ t: T?): T internal fun test(/*0*/ out: Out, /*1*/ i: In, /*2*/ inv: A): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit internal trait A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -24,10 +23,3 @@ internal trait Out { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/inference/constraints/subtypeConstraintOnNullableType.txt b/compiler/testData/diagnostics/tests/inference/constraints/subtypeConstraintOnNullableType.txt index 4e14f0c7c11..c261d61f606 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/subtypeConstraintOnNullableType.txt +++ b/compiler/testData/diagnostics/tests/inference/constraints/subtypeConstraintOnNullableType.txt @@ -3,7 +3,6 @@ package internal fun doOut(/*0*/ o: Out): T internal fun foo(/*0*/ a: A, /*1*/ o: Out): T internal fun test(/*0*/ a: A, /*1*/ aN: A, /*2*/ o: Out): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit internal trait A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -16,10 +15,3 @@ internal trait Out { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/inference/constraints/supertypeConstraintOnNullableType.txt b/compiler/testData/diagnostics/tests/inference/constraints/supertypeConstraintOnNullableType.txt index d5a8a8a9f92..a53f1e81a51 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/supertypeConstraintOnNullableType.txt +++ b/compiler/testData/diagnostics/tests/inference/constraints/supertypeConstraintOnNullableType.txt @@ -3,7 +3,6 @@ package internal fun doIn(/*0*/ i: In): T internal fun foo(/*0*/ a: A, /*1*/ i: In): T internal fun test(/*0*/ a: A, /*1*/ aN: A, /*2*/ i: In): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit internal trait A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -16,10 +15,3 @@ internal trait In { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.txt b/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.txt index 6fb29d949b1..bcd3f0e78c0 100644 --- a/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.txt +++ b/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.txt @@ -13,7 +13,6 @@ package a { internal fun testUpperBound(/*0*/ contrS: a.Contr, /*1*/ contrB: a.Contr, /*2*/ contrN: a.Contr): kotlin.Unit internal fun upperBound(/*0*/ t: T, /*1*/ l: a.Contr): T internal fun use(/*0*/ vararg a: kotlin.Any? /*kotlin.Array*/): kotlin.Array - internal fun T.checkType(/*0*/ f: (a._) -> kotlin.Unit): (a._) -> kotlin.Unit internal trait Contr { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -32,11 +31,4 @@ package a { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } - - internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedElvis.txt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedElvis.txt index 86ec85b9bd1..1217206da40 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedElvis.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedElvis.txt @@ -1,11 +1,3 @@ package internal fun foo(/*0*/ handlers: kotlin.Array?>): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedIf.txt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedIf.txt index 3e4accbf39c..52e6f8f1c65 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedIf.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/mixedIf.txt @@ -1,11 +1,3 @@ package internal fun foo(/*0*/ j: p.J): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/withNothing.txt b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/withNothing.txt index 7cf80e4b80a..b617cd7b052 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/withNothing.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/commonSupertype/withNothing.txt @@ -3,17 +3,9 @@ package internal fun f(/*0*/ a: Out, /*1*/ b: Out, /*2*/ c: Out): T internal fun out(/*0*/ t: T): Out> internal fun test(/*0*/ a: Out, /*1*/ b: Out>): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit internal trait Out { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleNoPackage.txt b/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleNoPackage.txt index 8712355dea2..3f61c3df959 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleNoPackage.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleNoPackage.txt @@ -1,11 +1,3 @@ package internal fun foo(/*0*/ f: kotlin.Int!): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleWithPackage.txt b/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleWithPackage.txt index 3eb50860a4e..a391b863135 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleWithPackage.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/explicitFlexibleWithPackage.txt @@ -2,12 +2,4 @@ package package ppp { internal fun foo(/*0*/ f: kotlin.Int!): kotlin.Unit - internal fun T.checkType(/*0*/ f: (ppp._) -> kotlin.Unit): (ppp._) -> kotlin.Unit - - internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/safeCall.txt b/compiler/testData/diagnostics/tests/platformTypes/safeCall.txt index 0f35ad75288..f35b67b61b7 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/safeCall.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/safeCall.txt @@ -1,11 +1,3 @@ package internal fun test(/*0*/ j: p.J): kotlin.Unit -internal fun T.checkType(/*0*/ f: (_) -> kotlin.Unit): (_) -> kotlin.Unit - -internal final class _ { - public constructor _() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/tests/org/jetbrains/jet/checkers/BaseDiagnosticsTest.java b/compiler/tests/org/jetbrains/jet/checkers/BaseDiagnosticsTest.java index 9a67db5e7fa..79415c63eb6 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/BaseDiagnosticsTest.java +++ b/compiler/tests/org/jetbrains/jet/checkers/BaseDiagnosticsTest.java @@ -24,7 +24,6 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Conditions; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; import com.intellij.psi.search.GlobalSearchScope; @@ -70,9 +69,13 @@ public abstract class BaseDiagnosticsTest extends JetLiteFixture { CheckerTestUtil.DebugInfoDiagnosticFactory.MISSING_UNRESOLVED, CheckerTestUtil.DebugInfoDiagnosticFactory.UNRESOLVED_WITH_TARGET ); + public static final String CHECK_TYPE_DIRECTIVE = "CHECK_TYPE"; - private static final String CHECK_TYPE_DECLARATIONS = "\nclass _" + + public static final String CHECK_TYPE_PACKAGE = "tests._checkType"; + private static final String CHECK_TYPE_DECLARATIONS = "\npackage " + CHECK_TYPE_PACKAGE + + "\nclass _" + "\nfun T.checkType(f: (_) -> Unit) = f"; + public static final String CHECK_TYPE_IMPORT = "import " + CHECK_TYPE_PACKAGE + ".*"; public static final String EXPLICIT_FLEXIBLE_TYPES_DIRECTIVE = "EXPLICIT_FLEXIBLE_TYPES"; public static final String EXPLICIT_FLEXIBLE_PACKAGE = Flexibility.FLEXIBLE_TYPE_CLASSIFIER.getPackageFqName().asString(); @@ -183,16 +186,23 @@ public abstract class BaseDiagnosticsTest extends JetLiteFixture { protected List getJetFiles(List testFiles, boolean includeExtras) { boolean declareFlexibleType = false; + boolean declareCheckType = false; List jetFiles = Lists.newArrayList(); for (TestFile testFile : testFiles) { if (testFile.getJetFile() != null) { jetFiles.add(testFile.getJetFile()); } declareFlexibleType |= testFile.declareFlexibleType; + declareCheckType |= testFile.declareCheckType; } - if (declareFlexibleType && includeExtras) { - jetFiles.add(createPsiFile(null, "EXPLICIT_FLEXIBLE_TYPES.kt", EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS)); + if (includeExtras) { + if (declareFlexibleType) { + jetFiles.add(createPsiFile(null, "EXPLICIT_FLEXIBLE_TYPES.kt", EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS)); + } + if (declareCheckType) { + jetFiles.add(createPsiFile(null, "CHECK_TYPE.kt", CHECK_TYPE_DECLARATIONS)); + } } return jetFiles; @@ -315,42 +325,58 @@ public abstract class BaseDiagnosticsTest extends JetLiteFixture { this.expectedText = this.clearText = textWithMarkers; } else { - expectedText = textWithMarkers; - clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges); - this.jetFile = createCheckAndReturnPsiFile(null, fileName, makeText()); + this.expectedText = textWithMarkers; + String textWithExtras = addExtras(expectedText); + this.clearText = CheckerTestUtil.parseDiagnosedRanges(textWithExtras, diagnosedRanges); + this.jetFile = createCheckAndReturnPsiFile(null, fileName, clearText); for (CheckerTestUtil.DiagnosedRange diagnosedRange : diagnosedRanges) { diagnosedRange.setFile(jetFile); } } } - private String makeText() { - String text = declareCheckType ? clearText + CHECK_TYPE_DECLARATIONS : clearText; - if (declareFlexibleType) { - Pattern pattern = Pattern.compile("^package [\\.\\w\\d]*\n", Pattern.MULTILINE); - Matcher matcher = pattern.matcher(text); - if (matcher.find()) { - // add import after the package directive - text = text.substring(0, matcher.end()) + EXPLICIT_FLEXIBLE_TYPES_IMPORT + "\n" + text.substring(matcher.end()); - } - else { - // add import at the beginning - text = EXPLICIT_FLEXIBLE_TYPES_IMPORT + "\n" + text; - } + @NotNull + private String getImports() { + String imports = ""; + if (declareCheckType) { + imports += CHECK_TYPE_IMPORT + "\n"; } - return text; + if (declareFlexibleType) { + imports += EXPLICIT_FLEXIBLE_TYPES_IMPORT + "\n"; + } + return imports; } - private void stripFlexibleTypes(StringBuilder actualText) { - if (declareFlexibleType) { - String pattern = EXPLICIT_FLEXIBLE_TYPES_IMPORT + "\n"; - int start = actualText.indexOf(pattern); - if (start >= 0) { - actualText.delete(start, start + pattern.length()); - } + private String getExtras() { + return "/*extras*/\n" + getImports() + "/*extras*/\n"; + } + + private String addExtras(String text) { + return addImports(text, getExtras()); + } + + private void stripExtras(StringBuilder actualText) { + String extras = getExtras(); + int start = actualText.indexOf(extras); + if (start >= 0) { + actualText.delete(start, start + extras.length()); } } + private String addImports(String text, String imports) { + Pattern pattern = Pattern.compile("^package [\\.\\w\\d]*\n", Pattern.MULTILINE); + Matcher matcher = pattern.matcher(text); + if (matcher.find()) { + // add imports after the package directive + text = text.substring(0, matcher.end()) + imports + text.substring(matcher.end()); + } + else { + // add imports at the beginning + text = imports + text; + } + return text; + } + @Nullable public TestModule getModule() { return module; @@ -398,12 +424,11 @@ public abstract class BaseDiagnosticsTest extends JetLiteFixture { actualText.append(CheckerTestUtil.addDiagnosticMarkersToText(jetFile, diagnostics, new Function() { @Override public String fun(PsiFile file) { - String text = file.getText(); - return declareCheckType ? StringUtil.trimEnd(text, CHECK_TYPE_DECLARATIONS) : text; + return file.getText(); } })); - stripFlexibleTypes(actualText); + stripExtras(actualText); return ok[0]; }