CHECK_TYPES injected through imports

This commit is contained in:
Andrey Breslav
2014-10-17 16:48:36 +04:00
parent 71d9ad5e8b
commit 0e42de4e99
17 changed files with 59 additions and 162 deletions
@@ -1,7 +1,6 @@
package
internal fun test(/*0*/ b: B): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> 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 _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -1,11 +1,3 @@
package
internal fun test(): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal final class _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -2,11 +2,3 @@ package
internal fun foo(): kotlin.Unit
internal fun </*0*/ T> id(/*0*/ t: T): T
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal final class _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -1,18 +1,10 @@
package
internal fun test(/*0*/ t: Tr<out kotlin.Any?>): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal trait Tr</*0*/ T> {
internal abstract var v: Tr<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 _</*0*/ T> {
public constructor _</*0*/ 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
}
}
@@ -1,18 +1,10 @@
package
internal fun test(/*0*/ t: Tr<out kotlin.Any?>): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal trait Tr</*0*/ T> {
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 _</*0*/ T> {
public constructor _</*0*/ 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
}
}
@@ -3,17 +3,9 @@ package
internal fun </*0*/ T> doA(/*0*/ a: A<T>): T
internal fun </*0*/ T> foo(/*0*/ a: A<T>, /*1*/ aN: A<T?>): T
internal fun test(/*0*/ a: A<kotlin.Int>, /*1*/ aN: A<kotlin.Int?>): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal trait A</*0*/ 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 _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -5,7 +5,6 @@ internal fun </*0*/ T : kotlin.Any> doIn(/*0*/ i: In<T?>): kotlin.Unit
internal fun </*0*/ T : kotlin.Any> doOut(/*0*/ o: Out<T?>): T
internal fun </*0*/ T : kotlin.Any> doT(/*0*/ t: T?): T
internal fun test(/*0*/ out: Out<kotlin.Int>, /*1*/ i: In<kotlin.Int>, /*2*/ inv: A<kotlin.Int>): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal trait A</*0*/ T> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@@ -24,10 +23,3 @@ internal trait Out</*0*/ out T> {
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -3,7 +3,6 @@ package
internal fun </*0*/ T> doOut(/*0*/ o: Out<T?>): T
internal fun </*0*/ T> foo(/*0*/ a: A<T>, /*1*/ o: Out<T?>): T
internal fun test(/*0*/ a: A<kotlin.Int>, /*1*/ aN: A<kotlin.Int?>, /*2*/ o: Out<kotlin.Int?>): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal trait A</*0*/ T> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@@ -16,10 +15,3 @@ internal trait Out</*0*/ out T> {
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -3,7 +3,6 @@ package
internal fun </*0*/ T> doIn(/*0*/ i: In<T?>): T
internal fun </*0*/ T> foo(/*0*/ a: A<T>, /*1*/ i: In<T>): T
internal fun test(/*0*/ a: A<kotlin.Int>, /*1*/ aN: A<kotlin.Int?>, /*2*/ i: In<kotlin.Int?>): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal trait A</*0*/ T> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@@ -16,10 +15,3 @@ internal trait In</*0*/ in T> {
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -13,7 +13,6 @@ package a {
internal fun testUpperBound(/*0*/ contrS: a.Contr<kotlin.String>, /*1*/ contrB: a.Contr<kotlin.Byte>, /*2*/ contrN: a.Contr<kotlin.Number>): kotlin.Unit
internal fun </*0*/ T> upperBound(/*0*/ t: T, /*1*/ l: a.Contr<T>): T
internal fun use(/*0*/ vararg a: kotlin.Any? /*kotlin.Array<kotlin.Any?>*/): kotlin.Array<kotlin.Any?>
internal fun </*0*/ T> T.checkType(/*0*/ f: (a._<T>) -> kotlin.Unit): (a._<T>) -> kotlin.Unit
internal trait Contr</*0*/ in T> {
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 _</*0*/ T> {
public constructor _</*0*/ 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
}
}
}
@@ -1,11 +1,3 @@
package
internal fun foo(/*0*/ handlers: kotlin.Array<kotlin.MutableList<kotlin.String>?>): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal final class _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -1,11 +1,3 @@
package
internal fun foo(/*0*/ j: p.J<kotlin.String>): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal final class _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -3,17 +3,9 @@ package
internal fun </*0*/ T> f(/*0*/ a: Out<T>, /*1*/ b: Out<T>, /*2*/ c: Out<T>): T
internal fun </*0*/ T> out(/*0*/ t: T): Out<kotlin.MutableList<T>>
internal fun test(/*0*/ a: Out<kotlin.Nothing>, /*1*/ b: Out<kotlin.MutableList<p.J>>): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal trait Out</*0*/ out T1> {
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 _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -1,11 +1,3 @@
package
internal fun foo(/*0*/ f: kotlin.Int!): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal final class _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -2,12 +2,4 @@ package
package ppp {
internal fun foo(/*0*/ f: kotlin.Int!): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (ppp._<T>) -> kotlin.Unit): (ppp._<T>) -> kotlin.Unit
internal final class _</*0*/ T> {
public constructor _</*0*/ 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
}
}
@@ -1,11 +1,3 @@
package
internal fun test(/*0*/ j: p.J): kotlin.Unit
internal fun </*0*/ T> T.checkType(/*0*/ f: (_<T>) -> kotlin.Unit): (_<T>) -> kotlin.Unit
internal final class _</*0*/ T> {
public constructor _</*0*/ 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
}
@@ -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 _<T>" +
public static final String CHECK_TYPE_PACKAGE = "tests._checkType";
private static final String CHECK_TYPE_DECLARATIONS = "\npackage " + CHECK_TYPE_PACKAGE +
"\nclass _<T>" +
"\nfun <T> T.checkType(f: (_<T>) -> 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<JetFile> getJetFiles(List<? extends TestFile> testFiles, boolean includeExtras) {
boolean declareFlexibleType = false;
boolean declareCheckType = false;
List<JetFile> 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<PsiFile, String>() {
@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];
}