diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java index 9ab5eb12ad1..70ade7d5dc9 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java @@ -500,11 +500,6 @@ public class TypeUtils { return typeParameterDescriptor != null && !typeParameterDescriptor.isReified(); } - public static boolean isReifiedTypeParameter(@NotNull KotlinType type) { - TypeParameterDescriptor typeParameterDescriptor = getTypeParameterDescriptorOrNull(type); - return typeParameterDescriptor != null && typeParameterDescriptor.isReified(); - } - @Nullable public static TypeParameterDescriptor getTypeParameterDescriptorOrNull(@NotNull KotlinType type) { if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) { diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 8000320dada..68aa9fcc268 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -1088,11 +1088,11 @@ fun main(args: Array) { model("reified/cases") } - testClass(javaClass()) { + testClass() { model("rtti/cases") } - testClass(javaClass()) { + testClass() { model("expression/cast/cases") } } diff --git a/js/js.libraries/src/core/javalang.kt b/js/js.libraries/src/core/javalang.kt index b4547a93b34..babe73f5ba1 100644 --- a/js/js.libraries/src/core/javalang.kt +++ b/js/js.libraries/src/core/javalang.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2016 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 java.lang @library @@ -27,7 +43,7 @@ public class NumberFormatException(message: String? = null) : RuntimeException(m @library public class NullPointerException(message: String? = null) : RuntimeException(message) {} -library +@library public class ClassCastException(message: String? = null) : RuntimeException(message) {} @library diff --git a/js/js.libraries/src/core/regex.kt b/js/js.libraries/src/core/regex.kt index 0f8dac9f3e5..031a6050fa0 100644 --- a/js/js.libraries/src/core/regex.kt +++ b/js/js.libraries/src/core/regex.kt @@ -217,7 +217,7 @@ private fun RegExp.findNext(input: String, from: Int): MatchResult? { get() { if (groupValues_ == null) { groupValues_ = object : java.util.AbstractList() { - override val size: Int get() = match.size + override val size: Int get() = match.length override fun get(index: Int): String = match[index] ?: "" } } diff --git a/js/js.libraries/src/core/regexp.kt b/js/js.libraries/src/core/regexp.kt index fbd77f51701..a3caa082a3f 100644 --- a/js/js.libraries/src/core/regexp.kt +++ b/js/js.libraries/src/core/regexp.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -45,6 +45,6 @@ public fun RegExp.reset() { public val input: String public val length: Int - nativeGetter - public fun get(index: Int): String? + @nativeGetter + public operator fun get(index: Int): String? } diff --git a/js/js.libraries/test/core/RegExpTest.kt b/js/js.libraries/test/core/RegExpTest.kt index d0a860d1a06..2429169a9ef 100644 --- a/js/js.libraries/test/core/RegExpTest.kt +++ b/js/js.libraries/test/core/RegExpTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -54,13 +54,13 @@ class RegExpTest { @test fun regExpExec() { val string = "R2D2 beats A5D5 " var re = RegExp("""(\w\d)(\w\d)""", "g") - val m1: Array = re.exec(string)!! - assertEquals(arrayOf("R2D2", "R2", "D2"), m1) + val m1 = re.exec(string)!! + assertEquals(arrayOf("R2D2", "R2", "D2"), m1.toArray()) assertEquals(0, m1.index) assertEquals(4, re.lastIndex) - val m2: Array = re.exec(string)!! - assertEquals(arrayOf("A5D5", "A5", "D5"), m2) + val m2 = re.exec(string)!! + assertEquals(arrayOf("A5D5", "A5", "D5"), m2.toArray()) assertEquals(string.indexOf(m2[0]!!), m2.index) val noMatch = re.exec(string) @@ -68,4 +68,9 @@ class RegExpTest { assertEquals(0, re.lastIndex) } + fun RegExpMatch.toArray(): Array { + val array = arrayOfNulls(length) + array.indices.forEach { array[it] = this[it] } + return array + } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java index 3a5ec13a38d..872c74fe76c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -326,9 +326,9 @@ public abstract class BasicTest extends KotlinTestWithEnvironment { @NotNull String moduleId, @NotNull EcmaVersion ecmaVersion, @Nullable List libraries, - List jetFiles + List jetFiles ) { - for (JetFile file : jetFiles) { + for (KtFile file : jetFiles) { String text = file.getText(); if (isDirectiveDefined(text, NO_INLINE_DIRECTIVE)) { diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CastTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CastTestGenerated.java index a7181de3232..c002eed85bc 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CastTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CastTestGenerated.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -18,7 +18,7 @@ package org.jetbrains.kotlin.js.test.semantics; import com.intellij.testFramework.TestDataPath; import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.JetTestUtils; +import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.TestMetadata; import org.junit.runner.RunWith; @@ -32,108 +32,108 @@ import java.util.regex.Pattern; @RunWith(JUnit3RunnerWithInners.class) public class CastTestGenerated extends AbstractCastTest { public void testAllFilesPresentInCases() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/expression/cast/cases"), Pattern.compile("^(.+)\\.kt$"), true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/expression/cast/cases"), Pattern.compile("^(.+)\\.kt$"), true); } @TestMetadata("castToAny.kt") public void testCastToAny() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToAny.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToAny.kt"); doTest(fileName); } @TestMetadata("castToArray.kt") public void testCastToArray() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToArray.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToArray.kt"); doTest(fileName); } @TestMetadata("castToFunction.kt") public void testCastToFunction() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToFunction.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToFunction.kt"); doTest(fileName); } @TestMetadata("castToGenericType.kt") public void testCastToGenericType() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToGenericType.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToGenericType.kt"); doTest(fileName); } @TestMetadata("castToGenericTypeWithUpperBound.kt") public void testCastToGenericTypeWithUpperBound() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToGenericTypeWithUpperBound.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToGenericTypeWithUpperBound.kt"); doTest(fileName); } @TestMetadata("castToNotNull.kt") public void testCastToNotNull() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToNotNull.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToNotNull.kt"); doTest(fileName); } @TestMetadata("castToNullable.kt") public void testCastToNullable() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToNullable.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToNullable.kt"); doTest(fileName); } @TestMetadata("reifiedToNotNull.kt") public void testReifiedToNotNull() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNotNull.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNotNull.kt"); doTest(fileName); } @TestMetadata("reifiedToNullable1.kt") public void testReifiedToNullable1() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNullable1.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNullable1.kt"); doTest(fileName); } @TestMetadata("reifiedToNullable2.kt") public void testReifiedToNullable2() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNullable2.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNullable2.kt"); doTest(fileName); } @TestMetadata("safeCastToGenericTypeWithUpperBound.kt") public void testSafeCastToGenericTypeWithUpperBound() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToGenericTypeWithUpperBound.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToGenericTypeWithUpperBound.kt"); doTest(fileName); } @TestMetadata("safeCastToNotNull.kt") public void testSafeCastToNotNull() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToNotNull.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToNotNull.kt"); doTest(fileName); } @TestMetadata("safeCastToNullable.kt") public void testSafeCastToNullable() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToNullable.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToNullable.kt"); doTest(fileName); } @TestMetadata("safeCastToReifiedNotNull.kt") public void testSafeCastToReifiedNotNull() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToReifiedNotNull.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToReifiedNotNull.kt"); doTest(fileName); } @TestMetadata("safeCastToReifiedNullable.kt") public void testSafeCastToReifiedNullable() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToReifiedNullable.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToReifiedNullable.kt"); doTest(fileName); } @TestMetadata("smartCastInExtensionFunction.kt") public void testSmartCastInExtensionFunction() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/smartCastInExtensionFunction.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/smartCastInExtensionFunction.kt"); doTest(fileName); } @TestMetadata("smartCastInFunction.kt") public void testSmartCastInFunction() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/smartCastInFunction.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/smartCastInFunction.kt"); doTest(fileName); } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/ReifiedTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/ReifiedTestGenerated.java index 35f2586d5d5..cfcc6593d01 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/ReifiedTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/ReifiedTestGenerated.java @@ -97,7 +97,7 @@ public class ReifiedTestGenerated extends AbstractReifiedTest { @TestMetadata("isTNullable.kt") public void testIsTNullable() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/reified/cases/isTNullable.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/reified/cases/isTNullable.kt"); doTest(fileName); } @@ -145,7 +145,7 @@ public class ReifiedTestGenerated extends AbstractReifiedTest { @TestMetadata("withInlineTurnedOff.kt") public void testWithInlineTurnedOff() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/reified/cases/withInlineTurnedOff.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/reified/cases/withInlineTurnedOff.kt"); doTest(fileName); } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/RttiTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/RttiTestGenerated.java index 9f12af40c56..b3b23ffa802 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/RttiTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/RttiTestGenerated.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -18,7 +18,7 @@ package org.jetbrains.kotlin.js.test.semantics; import com.intellij.testFramework.TestDataPath; import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.JetTestUtils; +import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.TestMetadata; import org.junit.runner.RunWith; @@ -32,72 +32,72 @@ import java.util.regex.Pattern; @RunWith(JUnit3RunnerWithInners.class) public class RttiTestGenerated extends AbstractRttiTest { public void testAllFilesPresentInCases() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/rtti/cases"), Pattern.compile("^(.+)\\.kt$"), true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/rtti/cases"), Pattern.compile("^(.+)\\.kt$"), true); } @TestMetadata("collectionClassesIsCheck.kt") public void testCollectionClassesIsCheck() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/collectionClassesIsCheck.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/collectionClassesIsCheck.kt"); doTest(fileName); } @TestMetadata("isComparable.kt") public void testIsComparable() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isComparable.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isComparable.kt"); doTest(fileName); } @TestMetadata("isJsPrimitiveType.kt") public void testIsJsPrimitiveType() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isJsPrimitiveType.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isJsPrimitiveType.kt"); doTest(fileName); } @TestMetadata("isSameClass.kt") public void testIsSameClass() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isSameClass.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isSameClass.kt"); doTest(fileName); } @TestMetadata("notIsOtherClass.kt") public void testNotIsOtherClass() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/notIsOtherClass.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/notIsOtherClass.kt"); doTest(fileName); } @TestMetadata("rttiForClass.kt") public void testRttiForClass() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForClass.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForClass.kt"); doTest(fileName); } @TestMetadata("rttiForTrait.kt") public void testRttiForTrait() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForTrait.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForTrait.kt"); doTest(fileName); } @TestMetadata("rttiForTrait2.kt") public void testRttiForTrait2() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForTrait2.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForTrait2.kt"); doTest(fileName); } @TestMetadata("sideEffectMethod.kt") public void testSideEffectMethod() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/sideEffectMethod.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/sideEffectMethod.kt"); doTest(fileName); } @TestMetadata("sideEffectProperty.kt") public void testSideEffectProperty() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/sideEffectProperty.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/sideEffectProperty.kt"); doTest(fileName); } @TestMetadata("stdlibEmptyListClass.kt") public void testStdlibEmptyListClass() throws Exception { - String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/stdlibEmptyListClass.kt"); + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/stdlibEmptyListClass.kt"); doTest(fileName); } } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java index ccd9bd27ebf..1767a0b5b85 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.js.translate.expression; import com.google.dart.compiler.backend.js.ast.*; -import com.google.dart.compiler.backend.js.ast.metadata.MetadataProperties; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.KtNodeTypes; @@ -25,9 +24,8 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor; import org.jetbrains.kotlin.descriptors.ClassDescriptor; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; -import org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsKt; import org.jetbrains.kotlin.js.patterns.NamePredicate; -import org.jetbrains.kotlin.js.patterns.typePredicates.TypePredicatesPackage; +import org.jetbrains.kotlin.js.patterns.typePredicates.TypePredicatesKt; import org.jetbrains.kotlin.js.translate.context.Namer; import org.jetbrains.kotlin.js.translate.context.TemporaryVariable; import org.jetbrains.kotlin.js.translate.context.TranslationContext; @@ -42,16 +40,18 @@ import org.jetbrains.kotlin.psi.KtIsExpression; import org.jetbrains.kotlin.psi.KtTypeReference; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.types.KotlinType; +import org.jetbrains.kotlin.types.TypeIntersector; -import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.*; -import static org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsPackage.getNameIfStandardType; import static org.jetbrains.kotlin.builtins.FunctionTypesKt.isFunctionTypeOrSubtype; import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isAnyOrNullableAny; import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isArray; +import static org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsKt.getNameIfStandardType; import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.equality; import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.negated; import static org.jetbrains.kotlin.psi.KtPsiUtil.findChildByType; -import static org.jetbrains.kotlin.types.TypeUtils.*; +import static org.jetbrains.kotlin.types.TypeUtils.getTypeParameterDescriptorOrNull; +import static org.jetbrains.kotlin.types.TypeUtils.isNullableType; +import static org.jetbrains.kotlin.types.TypeUtils.isReifiedTypeParameter; public final class PatternTranslator extends AbstractTranslator { @@ -143,7 +143,7 @@ public final class PatternTranslator extends AbstractTranslator { return getIsTypeCheckCallableForReifiedType(typeParameterDescriptor); } - return doGetIsTypeCheckCallable(typeParameterDescriptor.getUpperBoundsAsType()); + return doGetIsTypeCheckCallable(TypeIntersector.getUpperBoundsAsType(typeParameterDescriptor)); } JsNameRef typeName = getClassNameReference(type); @@ -154,18 +154,18 @@ public final class PatternTranslator extends AbstractTranslator { private JsExpression getIsTypeCheckCallableForBuiltin(@NotNull KotlinType type) { if (isAnyOrNullableAny(type)) return namer().isAny(); - if (isFunctionOrExtensionFunctionType(type)) return namer().isTypeOf(program().getStringLiteral("function")); + if (isFunctionTypeOrSubtype(type)) return namer().isTypeOf(program().getStringLiteral("function")); if (isArray(type)) return Namer.IS_ARRAY_FUN_REF; - if (TypePredicatesPackage.getCOMPARABLE().apply(type)) return namer().isComparable(); + if (TypePredicatesKt.getCOMPARABLE().apply(type)) return namer().isComparable(); return null; } @Nullable - private JsExpression getIsTypeCheckCallableForBuiltin(@NotNull KotlinType type) { - Name typeName = DescriptorUtilsKt.getNameIfStandardType(type); + private JsExpression getIsTypeCheckCallableForPrimitiveBuiltin(@NotNull KotlinType type) { + Name typeName = getNameIfStandardType(type); if (NamePredicate.STRING.apply(typeName)) { return namer().isTypeOf(program().getStringLiteral("string")); diff --git a/js/js.translator/testData/expression/cast/cases/castToGenericTypeWithUpperBound.kt b/js/js.translator/testData/expression/cast/cases/castToGenericTypeWithUpperBound.kt index 027b4a39eaf..78b17b2866c 100644 --- a/js/js.translator/testData/expression/cast/cases/castToGenericTypeWithUpperBound.kt +++ b/js/js.translator/testData/expression/cast/cases/castToGenericTypeWithUpperBound.kt @@ -4,13 +4,13 @@ open class A class B : A() class C -fun notNullToNotNullT(a: Any): T = a as T +fun notNullToNotNullT(a: Any): T = a as T -fun nullableToNotNullT(a: Any?): T = a as T +fun nullableToNotNullT(a: Any?): T = a as T -fun notNullToNullableT(a: Any): T? = a as T? +fun notNullToNullableT(a: Any): T? = a as T? -fun nullableToNullableT(a: Any?): T? = a as T? +fun nullableToNullableT(a: Any?): T? = a as T? fun box(): String { val a = A() diff --git a/js/js.translator/testData/expression/cast/cases/castToNotNull.kt b/js/js.translator/testData/expression/cast/cases/castToNotNull.kt index 9b89ea3f4ee..c034390394c 100644 --- a/js/js.translator/testData/expression/cast/cases/castToNotNull.kt +++ b/js/js.translator/testData/expression/cast/cases/castToNotNull.kt @@ -1,6 +1,6 @@ package foo -trait A +interface A class AImpl: A @@ -15,4 +15,4 @@ fun box(): String { failsClassCast("test(object{})") { test(object{}) } return "OK" -} \ No newline at end of file +} diff --git a/js/js.translator/testData/expression/cast/cases/reifiedToNotNull.kt b/js/js.translator/testData/expression/cast/cases/reifiedToNotNull.kt index 01c41b85866..dca58a573f0 100644 --- a/js/js.translator/testData/expression/cast/cases/reifiedToNotNull.kt +++ b/js/js.translator/testData/expression/cast/cases/reifiedToNotNull.kt @@ -2,12 +2,12 @@ package foo // CHECK_NOT_CALLED: test -trait A +interface A class AImpl: A inline -fun test(x: Any?): T = x as T +fun test(x: Any?): T = x as T fun box(): String { var a: A = AImpl() @@ -18,4 +18,4 @@ fun box(): String { failsClassCast("test(object{})") { test(object{}) } return "OK" -} \ No newline at end of file +} diff --git a/js/js.translator/testData/expression/cast/cases/reifiedToNullable1.kt b/js/js.translator/testData/expression/cast/cases/reifiedToNullable1.kt index f4e2d7d44b5..fb7c6ea52b3 100644 --- a/js/js.translator/testData/expression/cast/cases/reifiedToNullable1.kt +++ b/js/js.translator/testData/expression/cast/cases/reifiedToNullable1.kt @@ -5,7 +5,7 @@ interface A class AImpl : A {} inline -fun test(x: Any?): T = x as T +fun test(x: Any?): T = x as T fun box(): String { var a: A? = AImpl() @@ -16,4 +16,4 @@ fun box(): String { failsClassCast("test(object{})") { test(object{}) } return "OK" -} \ No newline at end of file +} diff --git a/js/js.translator/testData/expression/cast/cases/reifiedToNullable2.kt b/js/js.translator/testData/expression/cast/cases/reifiedToNullable2.kt index 5455eff71dc..3662554de22 100644 --- a/js/js.translator/testData/expression/cast/cases/reifiedToNullable2.kt +++ b/js/js.translator/testData/expression/cast/cases/reifiedToNullable2.kt @@ -5,7 +5,7 @@ interface A class AImpl : A {} inline -fun test(x: Any?): T? = x as T? +fun test(x: Any?): T? = x as T? fun box(): String { var a: A? = AImpl() @@ -16,4 +16,4 @@ fun box(): String { failsClassCast("test(object{})") { test(object{}) } return "OK" -} \ No newline at end of file +} diff --git a/js/js.translator/testData/expression/cast/cases/safeCastToGenericTypeWithUpperBound.kt b/js/js.translator/testData/expression/cast/cases/safeCastToGenericTypeWithUpperBound.kt index f8232ac2751..4126d1b0609 100644 --- a/js/js.translator/testData/expression/cast/cases/safeCastToGenericTypeWithUpperBound.kt +++ b/js/js.translator/testData/expression/cast/cases/safeCastToGenericTypeWithUpperBound.kt @@ -4,9 +4,9 @@ open class A class B : A() class C -fun notNullToNullableT(a: Any): T? = a as? T? +fun notNullToNullableT(a: Any): T? = a as? T? -fun nullableToNullableT(a: Any?): T? = a as? T? +fun nullableToNullableT(a: Any?): T? = a as? T? fun box(): String { val a = A() diff --git a/js/js.translator/testData/expression/cast/cases/safeCastToReifiedNotNull.kt b/js/js.translator/testData/expression/cast/cases/safeCastToReifiedNotNull.kt index ea19f6efd7a..eab0d24c022 100644 --- a/js/js.translator/testData/expression/cast/cases/safeCastToReifiedNotNull.kt +++ b/js/js.translator/testData/expression/cast/cases/safeCastToReifiedNotNull.kt @@ -6,7 +6,7 @@ class A class B inline -fun Any?.castTo(): T? = this as? T +fun Any?.castTo(): T? = this as? T fun box(): String { val a: Any? = A() @@ -18,4 +18,4 @@ fun box(): String { assertEquals(null, b.castTo(), "b") return "OK" -} \ No newline at end of file +} diff --git a/js/js.translator/testData/expression/cast/cases/safeCastToReifiedNullable.kt b/js/js.translator/testData/expression/cast/cases/safeCastToReifiedNullable.kt index 7e9ecebd5df..2486ad48114 100644 --- a/js/js.translator/testData/expression/cast/cases/safeCastToReifiedNullable.kt +++ b/js/js.translator/testData/expression/cast/cases/safeCastToReifiedNullable.kt @@ -6,7 +6,7 @@ class A class B inline -fun Any?.castTo(): T? = this as? T? +fun Any?.castTo(): T? = this as? T? fun box(): String { val a: Any? = A() @@ -18,4 +18,4 @@ fun box(): String { assertEquals(null, b.castTo(), "b") return "OK" -} \ No newline at end of file +} diff --git a/js/js.translator/testData/reified/cases/isTNullable.kt b/js/js.translator/testData/reified/cases/isTNullable.kt index fe9f5e8e4f2..79874c80b96 100644 --- a/js/js.translator/testData/reified/cases/isTNullable.kt +++ b/js/js.translator/testData/reified/cases/isTNullable.kt @@ -4,7 +4,7 @@ package foo // CHECK_NULLS_COUNT: function=box count=8 inline -fun Any?.isTypeOfOrNull() = this is T? +fun Any?.isTypeOfOrNull() = this is T? class A class B @@ -18,4 +18,4 @@ fun box(): String { assertEquals(false, A().isTypeOfOrNull(), "A().isTypeOfOrNull()") return "OK" -} \ No newline at end of file +}