Add ir interpreter tests
This commit is contained in:
committed by
TeamCityServer
parent
cc2d7340dc
commit
e28ab45c51
+697
@@ -0,0 +1,697 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.test.runners.ir.interpreter;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/ir/interpreter")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class IrInterpreterAfterFir2IrTestGenerated extends AbstractIrInterpreterAfterFir2IrTest {
|
||||
@Test
|
||||
@TestMetadata("abstract1.kt")
|
||||
public void testAbstract1() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/abstract1.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("abstract2.kt")
|
||||
public void testAbstract2() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/abstract2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("abstract3.kt")
|
||||
public void testAbstract3() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/abstract3.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("abstract4.kt")
|
||||
public void testAbstract4() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/abstract4.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInInterpreter() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true, "helpers");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayClassCast.kt")
|
||||
public void testArrayClassCast() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/arrayClassCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("branches.kt")
|
||||
public void testBranches() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/branches.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("companionOverride.kt")
|
||||
public void testCompanionOverride() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/companionOverride.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexReturn.kt")
|
||||
public void testComplexReturn() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/complexReturn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("composition.kt")
|
||||
public void testComposition() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/composition.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("copyReceivedValue.kt")
|
||||
public void testCopyReceivedValue() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/copyReceivedValue.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dataClass.kt")
|
||||
public void testDataClass() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/dataClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("defaultArgs.kt")
|
||||
public void testDefaultArgs() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/defaultArgs.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("defaultEquals.kt")
|
||||
public void testDefaultEquals() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/defaultEquals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("defaultHashCode.kt")
|
||||
public void testDefaultHashCode() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/defaultHashCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("defaultToString.kt")
|
||||
public void testDefaultToString() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/defaultToString.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("doWhileLoop.kt")
|
||||
public void testDoWhileLoop() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/doWhileLoop.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("doubleArrayOf.kt")
|
||||
public void testDoubleArrayOf() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/doubleArrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("elvis.kt")
|
||||
public void testElvis() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/elvis.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enums1.kt")
|
||||
public void testEnums1() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/enums1.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enums2.kt")
|
||||
public void testEnums2() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/enums2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enums3.kt")
|
||||
public void testEnums3() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/enums3.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extensionReceiver.kt")
|
||||
public void testExtensionReceiver() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/extensionReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("fib.kt")
|
||||
public void testFib() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/fib.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericListOfPairs.kt")
|
||||
public void testGenericListOfPairs() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/genericListOfPairs.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inKeyword.kt")
|
||||
public void testInKeyword() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/inKeyword.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineReturn.kt")
|
||||
public void testInlineReturn() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/inlineReturn.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("innerClass.kt")
|
||||
public void testInnerClass() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/innerClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("instanceOf.kt")
|
||||
public void testInstanceOf() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/instanceOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("instanceOfWithTypeParameters.kt")
|
||||
public void testInstanceOfWithTypeParameters() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/instanceOfWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interface.kt")
|
||||
public void testInterface() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/interface.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceDefault.kt")
|
||||
public void testInterfaceDefault() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/interfaceDefault.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambda.kt")
|
||||
public void testLambda() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/lambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localFunction.kt")
|
||||
public void testLocalFunction() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/localFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localObject.kt")
|
||||
public void testLocalObject() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/localObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("logIntrinsic.kt")
|
||||
public void testLogIntrinsic() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/logIntrinsic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("loop.kt")
|
||||
public void testLoop() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/loop.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("multipleOverridden.kt")
|
||||
public void testMultipleOverridden() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/multipleOverridden.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("object.kt")
|
||||
public void testObject() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/object.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("objectOverride.kt")
|
||||
public void testObjectOverride() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/objectOverride.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideDifferentName.kt")
|
||||
public void testOverrideDifferentName() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/overrideDifferentName.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideExtension.kt")
|
||||
public void testOverrideExtension() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/overrideExtension.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("progressionFromClosedRange.kt")
|
||||
public void testProgressionFromClosedRange() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/progressionFromClosedRange.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("rangeTo.kt")
|
||||
public void testRangeTo() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/rangeTo.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("regex.kt")
|
||||
public void testRegex() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/regex.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("safeClassCast.kt")
|
||||
public void testSafeClassCast() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/safeClassCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("scopeFunctions.kt")
|
||||
public void testScopeFunctions() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/scopeFunctions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("secondaryConstructor.kt")
|
||||
public void testSecondaryConstructor() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/secondaryConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("spreadOperator.kt")
|
||||
public void testSpreadOperator() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/spreadOperator.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("stringBuilder.kt")
|
||||
public void testStringBuilder() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/stringBuilder.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("stringConcatenation.kt")
|
||||
public void testStringConcatenation() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/stringConcatenation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("superClass.kt")
|
||||
public void testSuperClass() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/superClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/vararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("variableShadowing.kt")
|
||||
public void testVariableShadowing() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/variableShadowing.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("variables.kt")
|
||||
public void testVariables() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/variables.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("withReceivers.kt")
|
||||
public void testWithReceivers() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/withReceivers.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/ir/interpreter/collections")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Collections {
|
||||
@Test
|
||||
public void testAllFilesPresentInCollections() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/collections"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayConstructor.kt")
|
||||
public void testArrayConstructor() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/arrayConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOf.kt")
|
||||
public void testArrayOf() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("doubleList.kt")
|
||||
public void testDoubleList() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/doubleList.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("listOf.kt")
|
||||
public void testListOf() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/listOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("mapOf.kt")
|
||||
public void testMapOf() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/mapOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("matrixArray.kt")
|
||||
public void testMatrixArray() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/matrixArray.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("matrixList.kt")
|
||||
public void testMatrixList() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/matrixList.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("mutableListOf.kt")
|
||||
public void testMutableListOf() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/mutableListOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("mutableMapOf.kt")
|
||||
public void testMutableMapOf() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/mutableMapOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("mutableSetOf.kt")
|
||||
public void testMutableSetOf() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/mutableSetOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sequenceOf.kt")
|
||||
public void testSequenceOf() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/sequenceOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("setOf.kt")
|
||||
public void testSetOf() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/collections/setOf.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/ir/interpreter/exceptions")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Exceptions {
|
||||
@Test
|
||||
public void testAllFilesPresentInExceptions() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/exceptions"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arithmeticExceptionThrow.kt")
|
||||
public void testArithmeticExceptionThrow() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/arithmeticExceptionThrow.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arithmeticExceptionTryBlock.kt")
|
||||
public void testArithmeticExceptionTryBlock() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/arithmeticExceptionTryBlock.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arithmeticExceptionTryCatchFinally.kt")
|
||||
public void testArithmeticExceptionTryCatchFinally() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/arithmeticExceptionTryCatchFinally.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("classCastException.kt")
|
||||
public void testClassCastException() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/classCastException.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("commandsOutException.kt")
|
||||
public void testCommandsOutException() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/commandsOutException.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("divideByZero.kt")
|
||||
public void testDivideByZero() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/divideByZero.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("exceptionFromWrapper.kt")
|
||||
public void testExceptionFromWrapper() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/exceptionFromWrapper.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("exceptionWithCause.kt")
|
||||
public void testExceptionWithCause() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/exceptionWithCause.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("getCauseMessage.kt")
|
||||
public void testGetCauseMessage() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/getCauseMessage.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("multifileStackTrace.kt")
|
||||
public void testMultifileStackTrace() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/multifileStackTrace.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullPointerException.kt")
|
||||
public void testNullPointerException() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/nullPointerException.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("stackOverflow.kt")
|
||||
public void testStackOverflow() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/stackOverflow.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("stackTrace.kt")
|
||||
public void testStackTrace() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/stackTrace.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("tryFinally.kt")
|
||||
public void testTryFinally() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/exceptions/tryFinally.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/ir/interpreter/generatedStdlib")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class GeneratedStdlib {
|
||||
@Test
|
||||
public void testAllFilesPresentInGeneratedStdlib() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/generatedStdlib"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contains.kt")
|
||||
public void testContains() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/generatedStdlib/contains.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("elementAtOrElse.kt")
|
||||
public void testElementAtOrElse() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/generatedStdlib/elementAtOrElse.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("first.kt")
|
||||
public void testFirst() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/generatedStdlib/first.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("joinToString.kt")
|
||||
public void testJoinToString() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/generatedStdlib/joinToString.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("toList.kt")
|
||||
public void testToList() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/generatedStdlib/toList.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("trim.kt")
|
||||
public void testTrim() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/generatedStdlib/trim.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/ir/interpreter/jvm")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Jvm {
|
||||
@Test
|
||||
public void testAllFilesPresentInJvm() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/jvm"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("classReference.kt")
|
||||
public void testClassReference() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/jvm/classReference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaStatic.kt")
|
||||
public void testJavaStatic() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/jvm/javaStatic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kProperty2.kt")
|
||||
public void testKProperty2() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/jvm/kProperty2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("parameterReference.kt")
|
||||
public void testParameterReference() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/jvm/parameterReference.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/ir/interpreter/primitives")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Primitives {
|
||||
@Test
|
||||
public void testAllFilesPresentInPrimitives() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/primitives"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("charMethods.kt")
|
||||
public void testCharMethods() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/primitives/charMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intMethods.kt")
|
||||
public void testIntMethods() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/primitives/intMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("longMethods.kt")
|
||||
public void testLongMethods() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/primitives/longMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("uInt.kt")
|
||||
public void testUInt() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/primitives/uInt.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/ir/interpreter/proxy")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Proxy {
|
||||
@Test
|
||||
public void testAllFilesPresentInProxy() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/proxy"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("customCharSequence.kt")
|
||||
public void testCustomCharSequence() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/proxy/customCharSequence.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("customEquals.kt")
|
||||
public void testCustomEquals() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/proxy/customEquals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("proxyPair.kt")
|
||||
public void testProxyPair() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/proxy/proxyPair.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("superWrapper.kt")
|
||||
public void testSuperWrapper() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/proxy/superWrapper.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/ir/interpreter/reference")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Reference {
|
||||
@Test
|
||||
public void testAllFilesPresentInReference() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/interpreter/reference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyReference.kt")
|
||||
public void testPropertyReference() throws Exception {
|
||||
runTest("compiler/testData/ir/interpreter/reference/propertyReference.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
abstract class A @CompileTimeCalculation constructor() {
|
||||
@CompileTimeCalculation
|
||||
abstract fun getIntNum(): Int
|
||||
}
|
||||
|
||||
open class B @CompileTimeCalculation constructor(@CompileTimeCalculation val b: Int) : A() {
|
||||
@CompileTimeCalculation
|
||||
override fun getIntNum(): Int {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
class C @CompileTimeCalculation constructor(@CompileTimeCalculation val c: Int) : B(c + 1) {
|
||||
@CompileTimeCalculation
|
||||
override fun getIntNum(): Int {
|
||||
return c
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getAClassImplementation(num: Int): A {
|
||||
return B(num)
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getBClassImplementation(num: Int): B {
|
||||
return B(num)
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassCAsA(num: Int): A {
|
||||
return C(num)
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassCAsB(num: Int): B {
|
||||
return C(num)
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassCAsC(num: Int): C {
|
||||
return C(num)
|
||||
}
|
||||
|
||||
const val num1 = getAClassImplementation(1).<!EVALUATED: `1`!>getIntNum()<!>
|
||||
const val num2 = getBClassImplementation(2).<!EVALUATED: `2`!>getIntNum()<!>
|
||||
|
||||
// all `getIntNum` methods are from class C
|
||||
const val num3 = getClassCAsA(3).<!EVALUATED: `3`!>getIntNum()<!>
|
||||
const val num4 = getClassCAsB(4).<!EVALUATED: `4`!>getIntNum()<!>
|
||||
const val num5 = getClassCAsC(5).<!EVALUATED: `5`!>getIntNum()<!>
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
abstract class A @CompileTimeCalculation constructor() {
|
||||
@CompileTimeCalculation
|
||||
abstract fun getIntNum(): Int
|
||||
|
||||
@CompileTimeCalculation
|
||||
abstract fun getIntNumInverse(): Int
|
||||
}
|
||||
|
||||
abstract class B @CompileTimeCalculation constructor(@CompileTimeCalculation val b: Int) : A() {
|
||||
@CompileTimeCalculation
|
||||
override fun getIntNum(): Int {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
class C @CompileTimeCalculation constructor(@CompileTimeCalculation val c: Int) : B(c + 1) {
|
||||
@CompileTimeCalculation
|
||||
override fun getIntNum(): Int {
|
||||
return c
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
override fun getIntNumInverse(): Int {
|
||||
return -c
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassCAsA(num: Int): A {
|
||||
return C(num)
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassCAsB(num: Int): B {
|
||||
return C(num)
|
||||
}
|
||||
|
||||
// all methods call from C
|
||||
const val num1 = getClassCAsA(1).<!EVALUATED: `1`!>getIntNum()<!>
|
||||
const val num2 = getClassCAsB(2).<!EVALUATED: `2`!>getIntNum()<!>
|
||||
|
||||
const val num3 = getClassCAsA(3).<!EVALUATED: `-3`!>getIntNumInverse()<!>
|
||||
const val num4 = getClassCAsB(4).<!EVALUATED: `-4`!>getIntNumInverse()<!>
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
abstract class A @CompileTimeCalculation constructor() {
|
||||
@CompileTimeCalculation
|
||||
abstract fun getInt(): Int
|
||||
}
|
||||
|
||||
open class B @CompileTimeCalculation constructor(@CompileTimeCalculation val b: Int) : A() {
|
||||
@CompileTimeCalculation
|
||||
override fun getInt(): Int {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
abstract class C @CompileTimeCalculation constructor(@CompileTimeCalculation val c: Int) : B(c + 1) {
|
||||
@CompileTimeCalculation
|
||||
abstract fun getString(): String
|
||||
}
|
||||
|
||||
class D @CompileTimeCalculation constructor(@CompileTimeCalculation val d: Int) : C(d + 1) {
|
||||
@CompileTimeCalculation
|
||||
override fun getString(): String {
|
||||
return d.toString()
|
||||
}
|
||||
}
|
||||
@CompileTimeCalculation
|
||||
fun getClassDAsA(num: Int): A {
|
||||
return D(num)
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassDAsB(num: Int): B {
|
||||
return D(num)
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassDAsC(num: Int): C {
|
||||
return D(num)
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassDAsD(num: Int): D {
|
||||
return D(num)
|
||||
}
|
||||
|
||||
const val numA1 = getClassDAsA(1).<!EVALUATED: `3`!>getInt()<!>
|
||||
const val numB1 = getClassDAsB(1).<!EVALUATED: `3`!>getInt()<!>
|
||||
const val numC1 = getClassDAsC(1).<!EVALUATED: `3`!>getInt()<!>
|
||||
const val numC2 = getClassDAsC(1).<!EVALUATED: `1`!>getString()<!>
|
||||
const val numD1 = getClassDAsD(1).<!EVALUATED: `3`!>getInt()<!>
|
||||
const val numD2 = getClassDAsD(1).<!EVALUATED: `1`!>getString()<!>
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
@CompileTimeCalculation
|
||||
abstract class BaseIterator(var baseStart: Int) {
|
||||
fun baseNext(): Int {
|
||||
baseStart += 1
|
||||
return base()
|
||||
}
|
||||
|
||||
abstract fun base(): Int
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
abstract class ComplexIterator(var complexStart: Int) : BaseIterator(complexStart) {
|
||||
fun complexNext() = abstractCall()
|
||||
|
||||
private fun abstractCall(): Int {
|
||||
complexStart *= 2
|
||||
return complex() + baseNext()
|
||||
}
|
||||
|
||||
abstract fun complex(): Int
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
class ImplementIterator constructor(val i: Int) : ComplexIterator(i) {
|
||||
override fun complex(): Int {
|
||||
return complexStart
|
||||
}
|
||||
|
||||
override fun base(): Int {
|
||||
return baseStart
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getIterator(i: Int): ComplexIterator = ImplementIterator(i)
|
||||
|
||||
const val next = getIterator(10).<!EVALUATED: `31`!>complexNext()<!>
|
||||
@@ -0,0 +1,31 @@
|
||||
@CompileTimeCalculation
|
||||
fun <T> getArray(array: Array<T>) = array
|
||||
|
||||
const val a1 = <!EVALUATED: `true`!>getArray(arrayOf(1, 2.0, "3")) as? Array<Int> == null<!>
|
||||
const val a2 = <!EVALUATED: `false`!>getArray(arrayOf(1, 2, 3)) as? Array<Int> == null<!>
|
||||
const val a3 = <!EVALUATED: `true`!>getArray(arrayOf(1, 2, 3)) as? Array<Double> == null<!>
|
||||
const val a4 = <!EVALUATED: `false`!>getArray(arrayOf(1, 2, 3)) as? Array<Number> == null<!>
|
||||
|
||||
const val b1 = <!EVALUATED: `true`!>arrayOf(arrayOf(1, 2, 3)) as? Array<Array<String>> == null<!>
|
||||
const val b2 = <!EVALUATED: `false`!>arrayOf(arrayOf(1, 2, 3)) as? Array<Array<Int>> == null<!>
|
||||
const val b3 = <!EVALUATED: `false`!>arrayOf(arrayOf(1, 2, 3)) as? Array<Array<Number>> == null<!>
|
||||
|
||||
const val c1 = <!EVALUATED: `false`!>arrayOf(arrayOf(1, 2, 3), arrayOf("1", "2", "3"))[0] as? Array<Int> == null<!>
|
||||
const val c2 = <!EVALUATED: `false`!>arrayOf(arrayOf(1, 2, 3), arrayOf("1", "2", "3"))[1] as? Array<String> == null<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T, E> combineArrays(array1: Array<T>, array2: Array<E>) = arrayOf(array1, array2)
|
||||
|
||||
const val d1 = <!EVALUATED: `true`!>combineArrays(arrayOf(1, 2, 3), arrayOf(1, 2, 3)) as? Array<Array<Int>> == null<!>
|
||||
const val d2 = <!EVALUATED: `true`!>combineArrays(arrayOf(1, 2, 3), arrayOf(1, 2, 3)) as? Array<Array<Number>> == null<!>
|
||||
const val d3 = <!EVALUATED: `false`!>combineArrays(arrayOf(1, 2, 3), arrayOf(1, 2, 3)) as? Array<Array<Any>> == null<!>
|
||||
const val d4 = <!EVALUATED: `false`!>combineArrays(arrayOf(1, 2, 3), arrayOf(1, 2, 3)) as? Array<Array<*>> == null<!>
|
||||
const val d5 = <!EVALUATED: `false`!>combineArrays(arrayOf(1, 2, 3), arrayOf("1", "2", "3"))[0] as? Array<Int> == null<!>
|
||||
const val d6 = <!EVALUATED: `true`!>combineArrays(arrayOf(1, 2, 3), arrayOf("1", "2", "3"))[1] as? Array<Int> == null<!>
|
||||
const val d7 = <!EVALUATED: `false`!>combineArrays(arrayOf(1, 2, 3), arrayOf("1", "2", "3"))[1] as? Array<String> == null<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> echo(array: T) = array
|
||||
const val e1 = <!EVALUATED: `false`!>echo<Any>(arrayOf(1, 2, 3)) as? Array<Int> == null<!>
|
||||
const val e2 = <!EVALUATED: `false`!>echo<Any>(arrayOf(arrayOf(1, 2, 3))) as? Array<Array<Int>> == null<!>
|
||||
const val e3 = <!EVALUATED: `true`!>echo<Any>(arrayOf(echo<Any>(1), echo<Any>(2), echo<Any>(3))) as? Array<Int> == null<!>
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
@CompileTimeCalculation fun ifGreaterOrEqualToZero(a: Int): Boolean {
|
||||
return if (a >= 0) {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation fun whenGreaterOrEqualToZero(a: Int): Boolean {
|
||||
return when {
|
||||
a >= 0 -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation fun whenMultiBranch(a: Int): Int {
|
||||
return when (a) {
|
||||
1 -> -1
|
||||
2 -> -2
|
||||
3 -> -3
|
||||
4 -> -4
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
class A @CompileTimeCalculation constructor(@CompileTimeCalculation var a: Int)
|
||||
|
||||
@CompileTimeCalculation fun whenWithoutReturn(aObj: A): Int {
|
||||
when (aObj.a) {
|
||||
1 -> aObj.a = -1
|
||||
2 -> aObj.a = -2
|
||||
3 -> aObj.a = -3
|
||||
4 -> aObj.a = -4
|
||||
else -> aObj.a = 0
|
||||
}
|
||||
|
||||
return aObj.a
|
||||
}
|
||||
|
||||
@CompileTimeCalculation fun whenWithoutElse(aObj: A): Int {
|
||||
when (aObj.a) {
|
||||
1 -> aObj.a = -1
|
||||
2 -> aObj.a = -2
|
||||
3 -> aObj.a = -3
|
||||
4 -> aObj.a = -4
|
||||
}
|
||||
|
||||
return aObj.a
|
||||
}
|
||||
|
||||
const val a = <!EVALUATED: `true`!>ifGreaterOrEqualToZero(10)<!>
|
||||
const val b = <!EVALUATED: `false`!>whenGreaterOrEqualToZero(-10)<!>
|
||||
const val constIf = <!EVALUATED: `True`!>if (a == true) "True" else "False"<!>
|
||||
|
||||
const val multi1 = <!EVALUATED: `-2`!>whenMultiBranch(2)<!>
|
||||
const val multi2 = <!EVALUATED: `-4`!>whenMultiBranch(4)<!>
|
||||
const val multi3 = <!EVALUATED: `0`!>whenMultiBranch(10)<!>
|
||||
|
||||
const val c1 = <!EVALUATED: `-1`!>whenWithoutReturn(A(1))<!>
|
||||
const val c2 = <!EVALUATED: `-3`!>whenWithoutReturn(A(3))<!>
|
||||
const val c3 = <!EVALUATED: `0`!>whenWithoutReturn(A(10))<!>
|
||||
|
||||
const val d1 = <!EVALUATED: `-1`!>whenWithoutElse(A(1))<!>
|
||||
const val d2 = <!EVALUATED: `-4`!>whenWithoutElse(A(4))<!>
|
||||
const val d3 = <!EVALUATED: `10`!>whenWithoutElse(A(10))<!>
|
||||
@@ -0,0 +1,21 @@
|
||||
import kotlin.*
|
||||
|
||||
const val intArray1 = IntArray(42).<!EVALUATED: `42`!>size<!>
|
||||
const val intArray2 = <!EVALUATED: `0`!>IntArray(42)[0]<!>
|
||||
const val intArray3 = <!EVALUATED: `42`!>IntArray(10) { 42 }[0]<!>
|
||||
const val intArray4 = <!EVALUATED: `7`!>IntArray(10) { it -> it }[7]<!>
|
||||
|
||||
const val floatArray1 = FloatArray(42).<!EVALUATED: `42`!>size<!>
|
||||
const val floatArray2 = <!EVALUATED: `0.0`!>FloatArray(42)[0]<!>
|
||||
const val floatArray3 = <!EVALUATED: `42.5`!>FloatArray(10) { 42.5f }[0]<!>
|
||||
const val floatArray4 = <!EVALUATED: `7.0`!>FloatArray(10) { it -> it.toFloat() }[7]<!>
|
||||
|
||||
const val array = Array<Any?>(4) {
|
||||
when(it) {
|
||||
0 -> 1
|
||||
1 -> 2.0
|
||||
2 -> "3"
|
||||
3 -> null
|
||||
else -> throw IllegalArgumentException("$it is wrong")
|
||||
}
|
||||
}.<!EVALUATED: `1 2.0 3 null`!>let { it[0].toString() + " " + it[1] + " " + it[2] + " " + it[3] }<!>
|
||||
@@ -0,0 +1,23 @@
|
||||
@CompileTimeCalculation
|
||||
class A(val value: Int)
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun changeAndReturnSum(intArray: IntArray, index: Int, newValue: Int): Int {
|
||||
intArray[index] = newValue
|
||||
var sum = 0
|
||||
for (i in intArray) sum += i
|
||||
return sum
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun changeAndReturnSumForObject(array: Array<A>, index: Int, newValue: A): Int {
|
||||
array[index] = newValue
|
||||
var sum = 0
|
||||
for (aObject in array) sum += aObject.value
|
||||
return sum
|
||||
}
|
||||
|
||||
const val a = arrayOf(1, 2, 3).<!EVALUATED: `3`!>size<!>
|
||||
const val b = <!EVALUATED: `15`!>changeAndReturnSum(intArrayOf(1, 2, 3), 0, 10)<!>
|
||||
const val c = emptyArray<Int>().<!EVALUATED: `0`!>size<!>
|
||||
const val d = <!EVALUATED: `15`!>changeAndReturnSumForObject(arrayOf(A(1), A(2), A(3)), 0, A(10))<!>
|
||||
@@ -0,0 +1,25 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
const val doubleListSize = listOf(
|
||||
listOf("1", "2", "3"),
|
||||
listOf("4", "5", "6"),
|
||||
listOf("7", "8", "9")
|
||||
).<!EVALUATED: `3`!>size<!>
|
||||
|
||||
const val doubleListSizeOfList = listOf(
|
||||
listOf("1"),
|
||||
listOf("4", "5"),
|
||||
listOf("7", "8", "9")
|
||||
)[2].<!EVALUATED: `3`!>size<!>
|
||||
|
||||
const val doubleListGetSingleElement = <!EVALUATED: `9`!>listOf(
|
||||
listOf("1"),
|
||||
listOf("4", "5"),
|
||||
listOf("7", "8", "9")
|
||||
)[2][2]<!>
|
||||
|
||||
const val doubleListElements = listOf(
|
||||
listOf("1"),
|
||||
listOf("4", "5"),
|
||||
listOf("7", "8", "9")
|
||||
).<!EVALUATED: `1; 4, 5; 7, 8, 9`!>joinToString(separator = "; ") { it.joinToString() }<!>
|
||||
@@ -0,0 +1,16 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
const val a = listOf(1, 2, 3).<!EVALUATED: `3`!>size<!>
|
||||
const val b = emptyList<Int>().<!EVALUATED: `0`!>size<!>
|
||||
const val c = listOf<Int>().<!EVALUATED: `1`!>hashCode()<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getSum(list: List<Int>): Int {
|
||||
var sum: Int = 0
|
||||
for (element in list) {
|
||||
sum += element
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
const val sum = <!EVALUATED: `16`!>getSum(listOf(1, 3, 5, 7))<!>
|
||||
@@ -0,0 +1,18 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
|
||||
const val a = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `3`!>size<!>
|
||||
const val b = emptyMap<Any, Any>().<!EVALUATED: `0`!>size<!>
|
||||
|
||||
const val contains1 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `true`!>containsKey(1)<!>
|
||||
const val contains2 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `true`!>contains(1)<!>
|
||||
const val contains3 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `false`!>contains<Any, String>("1")<!>
|
||||
const val contains4 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `true`!>containsValue("1")<!>
|
||||
|
||||
const val get1 = <!EVALUATED: `1`!>mapOf(1 to "1", 2 to "2", 3 to "3").get(1)!!<!>
|
||||
const val get2 = <!EVALUATED: `2`!>mapOf(1 to "1", 2 to "2", 3 to "3")[2]!!<!>
|
||||
const val get3 = mapOf(1 to "1", 2 to "2", 3 to "3")[0].<!EVALUATED: `null`!>toString()<!>
|
||||
|
||||
const val keys = mapOf(1 to "1", 2 to "2", 3 to "3").keys.<!EVALUATED: `3`!>size<!>
|
||||
const val values = mapOf(1 to "1", 2 to "2", 3 to "3").values.<!EVALUATED: `3`!>size<!>
|
||||
const val entries = mapOf(1 to "1", 2 to "2", 3 to "3").entries.<!EVALUATED: `3`!>size<!>
|
||||
@@ -0,0 +1,40 @@
|
||||
import kotlin.*
|
||||
import kotlin.ranges.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
class MatrixNN(val values: Array<Array<Double>>) {
|
||||
val size = values.size
|
||||
operator fun times(other: MatrixNN): MatrixNN {
|
||||
val matrix = Array<Array<Double>>(size) { Array<Double>(size) { 0.0 } }
|
||||
for (i in 0 until size) {
|
||||
for (j in 0 until size) {
|
||||
for (k in 0 until size) {
|
||||
matrix[i][j] += this.values[i][k] * other.values[k][j]
|
||||
}
|
||||
}
|
||||
}
|
||||
return MatrixNN(matrix)
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun demo(): Double {
|
||||
val m1 = MatrixNN(
|
||||
arrayOf(
|
||||
arrayOf(3.0, 1.0, 0.0),
|
||||
arrayOf(1.0, 1.0, 0.0),
|
||||
arrayOf(0.0, 0.0, 1.0)
|
||||
)
|
||||
)
|
||||
val m2 = MatrixNN(
|
||||
arrayOf(
|
||||
arrayOf(3.0, 1.0, 1.0),
|
||||
arrayOf(1.0, 1.0, 1.0),
|
||||
arrayOf(1.0, 1.0, 1.0)
|
||||
)
|
||||
)
|
||||
|
||||
return (m1 * m2).values[0][0]
|
||||
}
|
||||
|
||||
const val temp = <!EVALUATED: `10.0`!>demo()<!>
|
||||
@@ -0,0 +1,41 @@
|
||||
import kotlin.*
|
||||
import kotlin.ranges.*
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
class MatrixNN(val values: List<List<Double>>) {
|
||||
val size = values.size
|
||||
operator fun times(other: MatrixNN): MatrixNN {
|
||||
val matrix = List<MutableList<Double>>(size) { MutableList<Double>(size) { 0.0 } }
|
||||
for (i in 0 until size) {
|
||||
for (j in 0 until size) {
|
||||
for (k in 0 until size) {
|
||||
matrix[i][j] = matrix[i][j] + (this.values[i][k] * other.values[k][j])
|
||||
}
|
||||
}
|
||||
}
|
||||
return MatrixNN(matrix)
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun demo(): Double {
|
||||
val m1 = MatrixNN(
|
||||
listOf(
|
||||
listOf(3.0, 1.0, 0.0),
|
||||
listOf(1.0, 1.0, 0.0),
|
||||
listOf(0.0, 0.0, 1.0)
|
||||
)
|
||||
)
|
||||
val m2 = MatrixNN(
|
||||
listOf(
|
||||
listOf(3.0, 1.0, 1.0),
|
||||
listOf(1.0, 1.0, 1.0),
|
||||
listOf(1.0, 1.0, 1.0)
|
||||
)
|
||||
)
|
||||
|
||||
return (m1 * m2).values[0][0]
|
||||
}
|
||||
|
||||
const val temp = <!EVALUATED: `10.0`!>demo()<!>
|
||||
@@ -0,0 +1,37 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testAdd(mutableList: MutableList<Int>, newElem: Int): String {
|
||||
mutableList.add(newElem)
|
||||
return "After add new size is " + mutableList.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> testRemove(mutableList: MutableList<T>, toRemove: T): String {
|
||||
mutableList.remove(toRemove)
|
||||
return "After remove new size is " + mutableList.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testAddAll(mutableList: MutableList<Double>, toAdd: List<Double>): String {
|
||||
mutableList.addAll(toAdd)
|
||||
return "After addAll new size is " + mutableList.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testIterator(mutableList: MutableList<Byte>): String {
|
||||
var sum = 0
|
||||
for (byte in mutableList) {
|
||||
sum += byte
|
||||
}
|
||||
return "Sum = " + sum
|
||||
}
|
||||
|
||||
const val emptyMutableListSize = mutableListOf<Any>().<!EVALUATED: `0`!>size<!>
|
||||
const val mutableListSize = mutableListOf(1, 2, 3).<!EVALUATED: `3`!>size<!>
|
||||
const val mutableListAdd = <!EVALUATED: `After add new size is 4`!>testAdd(mutableListOf(1, 2, 3), 4)<!>
|
||||
const val mutableListRemove1 = <!EVALUATED: `After remove new size is 2`!>testRemove(mutableListOf("1", "2", "3"), "1")<!>
|
||||
const val mutableListRemove2 = <!EVALUATED: `After remove new size is 3`!>testRemove(mutableListOf("1", "2", "3"), "4")<!>
|
||||
const val mutableListAddAll = <!EVALUATED: `After addAll new size is 5`!>testAddAll(mutableListOf(1.0, 2.0, 3.0), listOf(4.333, -5.5))<!>
|
||||
const val mutableListSum = <!EVALUATED: `Sum = 136`!>testIterator(mutableListOf<Byte>(1, (-2).toByte(), 127, 10, 0))<!>
|
||||
const val mutableListSubList = mutableListOf(1, 2, 3, 4).subList(0, 2).<!EVALUATED: `2`!>size<!>
|
||||
@@ -0,0 +1,6 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
|
||||
const val a1 = mutableMapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `3`!>size<!>
|
||||
const val a2 = mutableMapOf(1 to "1", 2 to "2", 3 to "3").apply { remove(1) }.<!EVALUATED: `2`!>size<!>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testAdd(mutableSet: MutableSet<Int>, newElem: Int): String {
|
||||
mutableSet.add(newElem)
|
||||
return "After add new size is " + mutableSet.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> testRemove(mutableSet: MutableSet<T>, toRemove: T): String {
|
||||
mutableSet.remove(toRemove)
|
||||
return "After remove new size is " + mutableSet.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testAddAll(mutableSet: MutableSet<Double>, toAdd: Set<Double>): String {
|
||||
mutableSet.addAll(toAdd)
|
||||
return "After addAll new size is " + mutableSet.size
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun testIterator(mutableSet: MutableSet<Byte>): String {
|
||||
var sum = 0
|
||||
for (byte in mutableSet) {
|
||||
sum += byte
|
||||
}
|
||||
return "Sum = " + sum
|
||||
}
|
||||
|
||||
const val emptyMutableSetSize = mutableSetOf<Any>().<!EVALUATED: `0`!>size<!>
|
||||
const val mutableSetSize = mutableSetOf(1, 2, 3).<!EVALUATED: `3`!>size<!>
|
||||
const val mutableSetAdd = <!EVALUATED: `After add new size is 4`!>testAdd(mutableSetOf(1, 2, 3), 4)<!>
|
||||
const val mutableSetRemove1 = <!EVALUATED: `After remove new size is 2`!>testRemove(mutableSetOf("1", "2", "3"), "1")<!>
|
||||
const val mutableSetRemove2 = <!EVALUATED: `After remove new size is 3`!>testRemove(mutableSetOf("1", "2", "3"), "4")<!>
|
||||
const val mutableSetAddAll = <!EVALUATED: `After addAll new size is 5`!>testAddAll(mutableSetOf(1.0, 2.0, 3.0), setOf(4.333, -5.5))<!>
|
||||
const val mutableSetSum = <!EVALUATED: `Sum = 136`!>testIterator(mutableSetOf<Byte>(1, (-2).toByte(), 127, 10, 0))<!>
|
||||
@@ -0,0 +1,6 @@
|
||||
import kotlin.sequences.*
|
||||
|
||||
const val a = sequenceOf(1, 2, 3).iterator().<!EVALUATED: `1`!>next()<!>
|
||||
const val b = sequenceOf(2, 3).iterator().<!EVALUATED: `2`!>next()<!>
|
||||
const val c = sequenceOf<Int>().iterator().<!EVALUATED: `false`!>hasNext()<!>
|
||||
const val d = generateSequence() { 42 }.iterator().<!EVALUATED: `42`!>next()<!>
|
||||
@@ -0,0 +1,17 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
const val a1 = setOf(1, 2, 3).<!EVALUATED: `3`!>size<!>
|
||||
const val a2 = setOf(1, 2, 3, 3, 2, 1).<!EVALUATED: `3`!>size<!>
|
||||
const val b = emptySet<Int>().<!EVALUATED: `0`!>size<!>
|
||||
const val c = setOf<Int>().<!EVALUATED: `0`!>hashCode()<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getSum(set: Set<Int>): Int {
|
||||
var sum: Int = 0
|
||||
for (element in set) {
|
||||
sum += element
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
const val sum = <!EVALUATED: `16`!>getSum(setOf(1, 3, 5, 7, 7, 5))<!>
|
||||
@@ -0,0 +1,32 @@
|
||||
@CompileTimeCalculation
|
||||
interface Object {
|
||||
fun get(): String
|
||||
|
||||
//@CompileTimeCalculation
|
||||
fun defaultGet() = "Object"
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
open class A {
|
||||
companion object : Object {
|
||||
@CompileTimeCalculation
|
||||
override fun get() = "A"
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
abstract class B : Object {
|
||||
fun str() = "B"
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
class C {
|
||||
companion object : B() {
|
||||
@CompileTimeCalculation
|
||||
override fun get() = "Default: " + super.defaultGet() + "; from super B: " + super.str() + "; from current: " + " companion C"
|
||||
}
|
||||
}
|
||||
|
||||
const val a = A.<!EVALUATED: `A`!>get()<!>
|
||||
const val c1 = C.<!EVALUATED: `Object`!>defaultGet()<!>
|
||||
const val c2 = C.<!EVALUATED: `Default: Object; from super B: B; from current: companion C`!>get()<!>
|
||||
@@ -0,0 +1,19 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> firstNotNull(list: List<T?>): T {
|
||||
for (elem in list) {
|
||||
return (elem ?: continue)
|
||||
}
|
||||
|
||||
throw kotlin.NoSuchElementException("All elements are null")
|
||||
}
|
||||
|
||||
const val a = <!EVALUATED: `1`!>firstNotNull(listOf(1, 2, 3))<!>
|
||||
const val b = <!EVALUATED: `1`!>firstNotNull(listOf(1, null, 3))<!>
|
||||
const val c = <!EVALUATED: `2`!>firstNotNull(listOf(null, 2, 3))<!>
|
||||
const val d = <!EVALUATED: `3`!>firstNotNull(listOf(null, null, 3))<!>
|
||||
const val e = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.util.NoSuchElementException: All elements are null
|
||||
at ComplexReturnKt.firstNotNull(complexReturn.kt:9)
|
||||
at ComplexReturnKt.<clinit>(complexReturn.kt:16)`!>firstNotNull(listOf<Int?>(null, null, null))<!>
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
open class A @CompileTimeCalculation constructor(@CompileTimeCalculation var a: Int) {
|
||||
@CompileTimeCalculation
|
||||
fun get(): Int {
|
||||
return a
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
open fun openGet(): Int {
|
||||
return a
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun setA(a: Int): A {
|
||||
this.a = a
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
open class B @CompileTimeCalculation constructor(@CompileTimeCalculation val b: Int) {
|
||||
@CompileTimeCalculation val aObj = A(b + 1)
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getAFromB(): Int {
|
||||
return aObj.a
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getFromProperty(): Int {
|
||||
return aObj.get()
|
||||
}
|
||||
}
|
||||
|
||||
open class C @CompileTimeCalculation constructor(@CompileTimeCalculation val c: Int) {
|
||||
@CompileTimeCalculation val aObj = A(c + 2)
|
||||
@CompileTimeCalculation val bObj = B(c + 1)
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getAFromC(): Int {
|
||||
return aObj.a
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getBFromC(): Int {
|
||||
return bObj.b
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun openGet(): Int {
|
||||
return aObj.openGet()
|
||||
}
|
||||
}
|
||||
|
||||
const val a1 = A(1).<!EVALUATED: `1`!>get()<!>
|
||||
const val a2 = A(1).setA(2).<!EVALUATED: `2`!>get()<!>
|
||||
const val a3 = A(1).<!EVALUATED: `1`!>openGet()<!>
|
||||
|
||||
const val b1 = B(1).<!EVALUATED: `2`!>getAFromB()<!>
|
||||
const val b2 = B(1).<!EVALUATED: `2`!>getFromProperty()<!>
|
||||
const val b3 = B(1).aObj.<!EVALUATED: `2`!>get()<!>
|
||||
const val b4 = B(1).aObj.setA(-1).<!EVALUATED: `-1`!>get()<!>
|
||||
const val b5 = B(1).aObj.<!EVALUATED: `2`!>a<!>
|
||||
|
||||
const val c1 = C(1).<!EVALUATED: `3`!>getAFromC()<!>
|
||||
const val c2 = C(1).<!EVALUATED: `2`!>getBFromC()<!>
|
||||
const val c3 = C(1).aObj.<!EVALUATED: `3`!>get()<!>
|
||||
const val c4 = C(1).<!EVALUATED: `3`!>openGet()<!>
|
||||
const val c5 = C(1).bObj.<!EVALUATED: `3`!>getAFromB()<!>
|
||||
const val c6 = C(1).bObj.<!EVALUATED: `3`!>getFromProperty()<!>
|
||||
const val c7 = C(1).bObj.aObj.setA(-2).<!EVALUATED: `-2`!>get()<!>
|
||||
const val c8 = C(1).bObj.<!EVALUATED: `2`!>b<!>
|
||||
const val c9 = C(1).aObj.<!EVALUATED: `3`!>a<!>
|
||||
@@ -0,0 +1,8 @@
|
||||
@CompileTimeCalculation
|
||||
fun Int.minusOne(): Int {
|
||||
var value = this
|
||||
value = value - 1
|
||||
return this
|
||||
}
|
||||
|
||||
const val a = 5.<!EVALUATED: `5`!>minusOne()<!>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
@CompileTimeCalculation
|
||||
data class Person(val name: String, val phone: Int)
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun Person.getAsString(): String {
|
||||
val (name, phone) = this
|
||||
return "Person name is $name and his phone is $phone"
|
||||
}
|
||||
|
||||
const val a1 = Person("John", 123456).<!EVALUATED: `John`!>name<!>
|
||||
const val a2 = Person("John", 123456).<!EVALUATED: `John`!>component1()<!>
|
||||
const val a3 = Person("John", 123456).<!EVALUATED: `123456`!>phone<!>
|
||||
const val a4 = Person("John", 123456).<!EVALUATED: `123456`!>component2()<!>
|
||||
|
||||
const val b1 = Person("John", 789).copy("Adam").<!EVALUATED: `Person(name=Adam, phone=789)`!>toString()<!>
|
||||
const val b2 = Person("John", 789).copy("Adam", 123).<!EVALUATED: `Person(name=Adam, phone=123)`!>toString()<!>
|
||||
|
||||
const val c = Person("John", 123456).<!EVALUATED: `true`!>equals(Person("John", 123456))<!>
|
||||
const val d = Person("John", 123456).<!EVALUATED: `Person name is John and his phone is 123456`!>getAsString()<!>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
@CompileTimeCalculation
|
||||
fun sum(a: Int = 1, b: Int = 2, c: Int = 3) = a + b + c
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun sumBasedOnPrevious(a: Int = 1, b: Int = a * 2, c: Int = b * 2) = a + b + c
|
||||
|
||||
const val sum1 = <!EVALUATED: `6`!>sum()<!>
|
||||
const val sum2 = <!EVALUATED: `1`!>sum(b = -3)<!>
|
||||
const val sum3 = <!EVALUATED: `3`!>sum(c = 1, a = 1, b = 1)<!>
|
||||
|
||||
const val sumBasedOnPrevious1 = <!EVALUATED: `7`!>sumBasedOnPrevious()<!>
|
||||
const val sumBasedOnPrevious2 = <!EVALUATED: `3`!>sumBasedOnPrevious(b = 1, c = 1)<!>
|
||||
@@ -0,0 +1,13 @@
|
||||
@CompileTimeCalculation
|
||||
class A
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getTheSameValue(a: Any): Any = a
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun theSameObjectEquals(value: Any): Boolean {
|
||||
return value == getTheSameValue(value) && value === getTheSameValue(value)
|
||||
}
|
||||
|
||||
const val equals1 = A().<!EVALUATED: `false`!>equals(A())<!>
|
||||
const val equals2 = <!EVALUATED: `true`!>theSameObjectEquals(A())<!>
|
||||
@@ -0,0 +1,59 @@
|
||||
@CompileTimeCalculation
|
||||
open class A
|
||||
|
||||
class B @CompileTimeCalculation constructor() {
|
||||
@CompileTimeCalculation
|
||||
override fun hashCode(): Int {
|
||||
return super.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
class C
|
||||
|
||||
class D : A()
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun checkHashCodeCorrectness(value: Any): Boolean {
|
||||
val hashCode = value.hashCode()
|
||||
return hashCode.toHex().length == 8 && hashCode == value.hashCode()
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getTheSameValue(a: Any): Any = a
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun theSameObjectHashCode(value: Any): Boolean {
|
||||
return value.hashCode() == getTheSameValue(value).hashCode()
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun Int.toHex(): String {
|
||||
val sb = StringBuilder()
|
||||
val hexDigits = charArrayOf(
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
)
|
||||
var value = this
|
||||
|
||||
var i = 8
|
||||
while (i > 0) {
|
||||
i -= 1
|
||||
val j = value.and(0x0F)
|
||||
sb.append(hexDigits[j])
|
||||
value = value.shr(4)
|
||||
}
|
||||
|
||||
return sb.reverse().toString()
|
||||
}
|
||||
|
||||
const val aHashCode = <!EVALUATED: `true`!>checkHashCodeCorrectness(A())<!>
|
||||
const val bHashCode = <!EVALUATED: `true`!>checkHashCodeCorrectness(B())<!>
|
||||
val cHashCode = C().hashCode() // must not be calculated
|
||||
val dHashCode = D().hashCode() // must not be calculated
|
||||
|
||||
const val arrayHashCode = <!EVALUATED: `true`!>checkHashCodeCorrectness(arrayOf(A(), B()))<!>
|
||||
const val intArrayHashCode = <!EVALUATED: `true`!>checkHashCodeCorrectness(arrayOf(1, 2, 3))<!>
|
||||
|
||||
const val checkA = <!EVALUATED: `true`!>theSameObjectHashCode(A())<!>
|
||||
const val checkStringBuilder1 = <!EVALUATED: `true`!>theSameObjectHashCode(StringBuilder())<!>
|
||||
const val checkStringBuilder2 = <!EVALUATED: `true`!>theSameObjectHashCode(StringBuilder("Some Builder"))<!>
|
||||
@@ -0,0 +1,39 @@
|
||||
@CompileTimeCalculation
|
||||
open class A
|
||||
|
||||
class B @CompileTimeCalculation constructor() {
|
||||
@CompileTimeCalculation
|
||||
override fun toString(): String {
|
||||
return super.toString()
|
||||
}
|
||||
}
|
||||
|
||||
class C
|
||||
|
||||
class D : A()
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun checkToStringCorrectness(value: Any, startStr: String): Boolean {
|
||||
val string = value.toString()
|
||||
return string.subSequence(0, startStr.length) == startStr && string.get(startStr.length) == '@' && string.length <= startStr.length + 9
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getTheSameValue(a: Any): Any = a
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun theSameObjectToString(value: Any): Boolean {
|
||||
return value.toString() == getTheSameValue(value).toString()
|
||||
}
|
||||
|
||||
const val aString = <!EVALUATED: `true`!>checkToStringCorrectness(A(), "A")<!>
|
||||
const val bString = <!EVALUATED: `true`!>checkToStringCorrectness(B(), "B")<!>
|
||||
val cString = C().toString() // must not be calculated
|
||||
val dString = D().toString() // must not be calculated
|
||||
|
||||
const val arrayString = <!EVALUATED: `true`!>checkToStringCorrectness(arrayOf(A(), B()).toString(), "[Ljava.lang.Object;")<!>
|
||||
const val intArrayString = <!EVALUATED: `true`!>checkToStringCorrectness(intArrayOf(1, 2, 3).toString(), "[I")<!>
|
||||
|
||||
const val checkA = <!EVALUATED: `true`!>theSameObjectToString(A())<!>
|
||||
const val checkStringBuilder1 = <!EVALUATED: `true`!>theSameObjectToString(StringBuilder())<!>
|
||||
const val checkStringBuilder2 = <!EVALUATED: `true`!>theSameObjectToString(StringBuilder("Some Builder"))<!>
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
@CompileTimeCalculation
|
||||
fun factorialDoWhile(num: Int): Int {
|
||||
var number = num
|
||||
var factorial = 1
|
||||
|
||||
do {
|
||||
factorial *= number
|
||||
number--
|
||||
} while (number > 0)
|
||||
|
||||
return factorial
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun firstNotNull(array: Array<Int?>): Int {
|
||||
var i = 0
|
||||
|
||||
do {
|
||||
val y = array[i++]
|
||||
} while (y == null)
|
||||
|
||||
return array[i - 1]!!
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun singleExpressionLoop(incrementTo: Int): Int {
|
||||
var i = 0
|
||||
do i++ while (i < incrementTo)
|
||||
return i
|
||||
}
|
||||
|
||||
const val a = <!EVALUATED: `720`!>factorialDoWhile(6)<!>
|
||||
const val b = <!EVALUATED: `1`!>firstNotNull(arrayOf<Int?>(null, null, 1, 2, null))<!>
|
||||
const val c = <!EVALUATED: `10`!>singleExpressionLoop(10)<!>
|
||||
@@ -0,0 +1,13 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
const val doubleArray = arrayOf(
|
||||
arrayOf(1, 2, 3),
|
||||
arrayOf(4, 5),
|
||||
arrayOf(6)
|
||||
).<!EVALUATED: `1, 2, 3; 4, 5; 6`!>joinToString(separator = "; ") { it.joinToString() }<!>
|
||||
|
||||
const val doubleUintArray = arrayOf(
|
||||
arrayOf(1u, 2u, 3u),
|
||||
arrayOf(4u, 5u),
|
||||
arrayOf(6u)
|
||||
).<!EVALUATED: `1, 2, 3; 4, 5; 6`!>joinToString(separator = "; ") { it.joinToString() }<!>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@CompileTimeCalculation
|
||||
fun getLenght(value: String?): Int = value?.length ?: -1
|
||||
|
||||
const val a1 = <!EVALUATED: `5`!>getLenght("Elvis")<!>
|
||||
const val a2 = <!EVALUATED: `-1`!>getLenght(null)<!>
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
enum class EnumClass {
|
||||
VALUE1, VALUE2
|
||||
}
|
||||
|
||||
const val a = EnumClass.VALUE1.<!EVALUATED: `VALUE1`!>name<!>
|
||||
const val b = EnumClass.values().<!EVALUATED: `2`!>size<!>
|
||||
const val c = EnumClass.valueOf("VALUE1").<!EVALUATED: `0`!>ordinal<!>
|
||||
const val d = EnumClass.valueOf("VALUE3").<!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.IllegalArgumentException: No enum constant EnumClass.VALUE3
|
||||
at Enums1Kt.EnumClass.valueOf(enums1.kt)
|
||||
at Enums1Kt.<clinit>(enums1.kt:12)`!>ordinal<!>
|
||||
|
||||
const val e1 = EnumClass.VALUE1.hashCode().<!EVALUATED: `true`!>let { it is Int && it > 0 && it == EnumClass.VALUE1.hashCode() }<!>
|
||||
const val e2 = EnumClass.VALUE1.<!EVALUATED: `VALUE1`!>toString()<!>
|
||||
const val e3 = <!EVALUATED: `true`!>EnumClass.VALUE1 == EnumClass.VALUE1<!>
|
||||
const val e4 = <!EVALUATED: `false`!>EnumClass.VALUE1 == EnumClass.VALUE2<!>
|
||||
|
||||
const val f1 = enumValues<EnumClass>().<!EVALUATED: `2`!>size<!>
|
||||
const val f2 = enumValueOf<EnumClass>("VALUE1").<!EVALUATED: `VALUE1`!>name<!>
|
||||
|
||||
const val j1 = enumValues<EnumClass>().<!EVALUATED: `VALUE1, VALUE2`!>joinToString { it.name }<!>
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
@CompileTimeCalculation
|
||||
enum class Empty
|
||||
|
||||
@CompileTimeCalculation
|
||||
enum class Color(val rgb: Int) {
|
||||
BLACK() { override fun getColorAsString() = "0x000000" },
|
||||
RED(0xFF0000) { override fun getColorAsString() = "0xFF0000" },
|
||||
GREEN(0x00FF00) { override fun getColorAsString() = "0x00FF00" },
|
||||
BLUE(0x0000FF) { override fun getColorAsString() = "0x0000FF" };
|
||||
|
||||
constructor() : this(0x000000) {}
|
||||
|
||||
abstract fun getColorAsString(): String
|
||||
|
||||
fun getColorAsInt(): Int = rgb
|
||||
}
|
||||
|
||||
const val a1 = Empty.values().<!EVALUATED: `0`!>size<!>
|
||||
const val a2 = enumValues<Empty>().<!EVALUATED: `0`!>size<!>
|
||||
|
||||
const val b1 = Color.BLACK.<!EVALUATED: `BLACK`!>name<!>
|
||||
const val b2 = Color.BLACK.<!EVALUATED: `0x000000`!>getColorAsString()<!>
|
||||
const val b3 = Color.RED.<!EVALUATED: `0xFF0000`!>getColorAsString()<!>
|
||||
|
||||
const val c1 = Color.BLACK.<!EVALUATED: `0`!>getColorAsInt()<!>
|
||||
const val c2 = Color.RED.<!EVALUATED: `16711680`!>getColorAsInt()<!>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import kotlin.text.*
|
||||
|
||||
const val a = RegexOption.IGNORE_CASE.<!EVALUATED: `IGNORE_CASE`!>name<!>
|
||||
const val b = RegexOption.IGNORE_CASE.<!EVALUATED: `0`!>ordinal<!>
|
||||
const val c = RegexOption.MULTILINE.<!EVALUATED: `MULTILINE`!>name<!>
|
||||
const val d = RegexOption.MULTILINE.<!EVALUATED: `1`!>ordinal<!>
|
||||
const val e = <!EVALUATED: `true`!>RegexOption.IGNORE_CASE == RegexOption.IGNORE_CASE<!>
|
||||
const val f = <!EVALUATED: `true`!>RegexOption.IGNORE_CASE != RegexOption.MULTILINE<!>
|
||||
const val g = RegexOption.IGNORE_CASE.<!EVALUATED: `IGNORE_CASE`!>toString()<!>
|
||||
@@ -0,0 +1,88 @@
|
||||
@CompileTimeCalculation
|
||||
fun throwExample(a: Int, b: Int): Int {
|
||||
if (b == 0) throw ArithmeticException("Divide by zero")
|
||||
return a / b
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun throwNullMessage(a: Int, b: Int): Int {
|
||||
if (b == 0) throw ArithmeticException(null)
|
||||
return a / b
|
||||
}
|
||||
|
||||
const val a1 = <!EVALUATED: `false`!>try {
|
||||
throwExample(10, 0)
|
||||
true
|
||||
} catch (e: ArithmeticException) {
|
||||
false
|
||||
}<!>
|
||||
const val a2 = <!EVALUATED: `true`!>try {
|
||||
throwExample(10, 1)
|
||||
true
|
||||
} catch (e: ArithmeticException) {
|
||||
false
|
||||
}<!>
|
||||
|
||||
const val b1 = <!EVALUATED: `false`!>try {
|
||||
throwExample(10, 0)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}<!>
|
||||
const val b2 = <!EVALUATED: `true`!>try {
|
||||
throwExample(10, 1)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}<!>
|
||||
const val b3 = <!EVALUATED: `false`!>try {
|
||||
throwExample(10, 0)
|
||||
true
|
||||
} catch (e: Throwable) {
|
||||
false
|
||||
}<!>
|
||||
|
||||
const val c1 = <!EVALUATED: `1`!>try {
|
||||
throwExample(10, 0)
|
||||
0
|
||||
} catch (e: ArithmeticException) {
|
||||
1
|
||||
} catch (e: Exception) {
|
||||
2
|
||||
}<!>
|
||||
const val c2 = <!EVALUATED: `1`!>try {
|
||||
throwExample(10, 0)
|
||||
0
|
||||
} catch (e: Exception) {
|
||||
1
|
||||
} catch (e: ArithmeticException) {
|
||||
2
|
||||
}<!>
|
||||
const val c3 = <!EVALUATED: `2`!>try {
|
||||
throwExample(10, 0)
|
||||
0
|
||||
} catch (e: NullPointerException) {
|
||||
1
|
||||
} catch (e: ArithmeticException) {
|
||||
2
|
||||
}<!>
|
||||
|
||||
const val d1 = <!EVALUATED: `Divide by zero`!>try {
|
||||
throwExample(10, 0)
|
||||
"Without exception"
|
||||
} catch (e: ArithmeticException) {
|
||||
e.message ?: "Exception without message"
|
||||
}<!>
|
||||
const val d2 = <!EVALUATED: `Without exception`!>try {
|
||||
throwExample(10, 1)
|
||||
"Without exception"
|
||||
} catch (e: ArithmeticException) {
|
||||
e.message ?: "Exception without message"
|
||||
}<!>
|
||||
|
||||
const val nullMessage = <!EVALUATED: `Exception without message`!>try {
|
||||
throwNullMessage(10, 0)
|
||||
"Without exception"
|
||||
} catch (e: ArithmeticException) {
|
||||
e.message ?: "Exception without message"
|
||||
}<!>
|
||||
@@ -0,0 +1,28 @@
|
||||
@CompileTimeCalculation
|
||||
fun tryCatch(integer: Int): Boolean {
|
||||
try {
|
||||
val a = 10 / integer
|
||||
return true
|
||||
} catch (e: ArithmeticException) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const val a1 = <!EVALUATED: `false`!>tryCatch(0)<!>
|
||||
const val a2 = <!EVALUATED: `true`!>tryCatch(1)<!>
|
||||
const val a3 = <!EVALUATED: `true`!>tryCatch(100)<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun multiTryCatch(integer: Int): String {
|
||||
return try {
|
||||
val a = 10 / integer
|
||||
"Normal"
|
||||
} catch (e: AssertionError) {
|
||||
"AssertionError"
|
||||
} catch (e: ArithmeticException) {
|
||||
"ArithmeticException"
|
||||
}
|
||||
}
|
||||
|
||||
const val b1 = <!EVALUATED: `ArithmeticException`!>multiTryCatch(0)<!>
|
||||
const val b2 = <!EVALUATED: `Normal`!>multiTryCatch(1)<!>
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
@CompileTimeCalculation
|
||||
fun tryCatch(integer: Int): String {
|
||||
var str = ""
|
||||
try {
|
||||
str += "Start dividing\n"
|
||||
val a = 10 / integer
|
||||
str += "Without exception\n"
|
||||
} catch (e: ArithmeticException) {
|
||||
str += "Exception\n"
|
||||
} finally {
|
||||
str += "Finally\n"
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
const val a1 = <!EVALUATED: `Start dividing
|
||||
Exception
|
||||
Finally
|
||||
`!>tryCatch(0)<!>
|
||||
const val a2 = <!EVALUATED: `Start dividing
|
||||
Without exception
|
||||
Finally
|
||||
`!>tryCatch(1)<!>
|
||||
const val a3 = <!EVALUATED: `Start dividing
|
||||
Without exception
|
||||
Finally
|
||||
`!>tryCatch(100)<!>
|
||||
@@ -0,0 +1,73 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun classCastWithException(a: Any): String {
|
||||
return try {
|
||||
a as Int
|
||||
"Given value is $a and its doubled value is ${2 * a}"
|
||||
} catch (e: ClassCastException) {
|
||||
"Given value isnt't Int; Exception message: \"${e.message}\""
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun safeClassCast(a: Any): Int {
|
||||
return (a as? String)?.length ?: -1
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> unsafeClassCast(): T {
|
||||
return 1 as T
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> getIntList() = listOf<Int>(1, 2) as T
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> getStringNullableList() = listOf<String?>(null, "1") as T
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getLength(str: String) = str.length
|
||||
|
||||
@CompileTimeCalculation
|
||||
class A<T>() {
|
||||
fun unsafeCast(): T {
|
||||
return 1 as T
|
||||
}
|
||||
}
|
||||
|
||||
const val a1 = <!EVALUATED: `Given value is 10 and its doubled value is 20`!>classCastWithException(10)<!>
|
||||
const val a2 = <!EVALUATED: `Given value isnt't Int; Exception message: "kotlin.String cannot be cast to kotlin.Int"`!>classCastWithException("10")<!>
|
||||
|
||||
const val b1 = <!EVALUATED: `-1`!>safeClassCast(10)<!>
|
||||
const val b2 = <!EVALUATED: `2`!>safeClassCast("10")<!>
|
||||
|
||||
// in this example all unsafe cast will be "successful", but will fall when trying to assign
|
||||
const val c1 = <!EVALUATED: `1`!>unsafeClassCast<Int>()<!>
|
||||
const val c2 = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.ClassCastException: kotlin.Int cannot be cast to kotlin.String
|
||||
at ClassCastExceptionKt.unsafeClassCast(classCastException.kt:21)
|
||||
at ClassCastExceptionKt.<clinit>(classCastException.kt:48)`!>unsafeClassCast<String>()<!>
|
||||
|
||||
const val d1 = A<Int>().<!EVALUATED: `1`!>unsafeCast()<!>
|
||||
const val d2 = A<String>().<!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.ClassCastException: kotlin.Int cannot be cast to kotlin.String
|
||||
at ClassCastExceptionKt.A.unsafeCast(classCastException.kt:36)
|
||||
at ClassCastExceptionKt.<clinit>(classCastException.kt:51)`!>unsafeCast()<!>
|
||||
|
||||
const val stringList = getIntList<List<String>>().<!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.ClassCastException: kotlin.Int cannot be cast to kotlin.String
|
||||
at ClassCastExceptionKt.stringList.<anonymous>(classCastException.kt:54)
|
||||
at StandardKt.kotlin.let(Standard.kt:32)
|
||||
at ClassCastExceptionKt.<clinit>(classCastException.kt:53)`!>let {
|
||||
it[0].length
|
||||
}<!>
|
||||
const val nullableStringList = getStringNullableList<List<String>>().<!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.NullPointerException
|
||||
at ClassCastExceptionKt.nullableStringList.<anonymous>(classCastException.kt)
|
||||
at StandardKt.kotlin.let(Standard.kt:32)
|
||||
at ClassCastExceptionKt.<clinit>(classCastException.kt:56)`!>let { it[0].length }<!>
|
||||
const val nullableStringLength = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.IllegalArgumentException: Parameter specified as non-null is null: method ClassCastExceptionKt.getLength, parameter str
|
||||
at ClassCastExceptionKt.<clinit>(classCastException.kt:31)`!>getLength(getStringNullableList<List<String>>()[0])<!>
|
||||
@@ -0,0 +1,10 @@
|
||||
@CompileTimeCalculation
|
||||
fun infinityWhile(): Int {
|
||||
while (true) {}
|
||||
return 0
|
||||
}
|
||||
|
||||
const val a = <!WAS_NOT_EVALUATED: `
|
||||
Exception org.jetbrains.kotlin.ir.interpreter.exceptions.InterpreterTimeOutError: Exceeded execution limit of constexpr expression
|
||||
at CommandsOutExceptionKt.infinityWhile(commandsOutException.kt:3)
|
||||
at CommandsOutExceptionKt.<clinit>(commandsOutException.kt:7)`!>infinityWhile()<!>
|
||||
@@ -0,0 +1,15 @@
|
||||
const val a = <!EVALUATED: `1`!>try {
|
||||
10 / 0
|
||||
0
|
||||
} catch (e: RuntimeException) {
|
||||
1
|
||||
}<!>
|
||||
|
||||
const val b = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.ArithmeticException: / by zero
|
||||
at DivideByZeroKt.<clinit>(divideByZero.kt:8)`!>10 / 0<!>
|
||||
|
||||
// not working for now, but maybe will be supported
|
||||
//fun someFunWithCompileTimeInside() {
|
||||
// val exceptionExpected = 1 / 0
|
||||
//}
|
||||
@@ -0,0 +1,12 @@
|
||||
@CompileTimeCalculation
|
||||
fun append(sb: StringBuilder, value: CharSequence, start: Int, end: Int): String {
|
||||
return sb.append(value, start, end).toString()
|
||||
}
|
||||
|
||||
const val a = <!EVALUATED: `Some string with not zero length!!!`!>append(StringBuilder("Some string with not zero length"), "!!!", 0, 3)<!>
|
||||
const val b = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.IndexOutOfBoundsException: start -1, end 0, s.length() 3
|
||||
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:539)
|
||||
at java.lang.StringBuilder.append(StringBuilder.java:175)
|
||||
at ExceptionFromWrapperKt.append(exceptionFromWrapper.kt:3)
|
||||
at ExceptionFromWrapperKt.<clinit>(exceptionFromWrapper.kt:7)`!>append(StringBuilder("Some string with not zero length"), "!!!", -1, 0)<!>
|
||||
@@ -0,0 +1,49 @@
|
||||
// https://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Throwable.html#printStackTrace()
|
||||
@CompileTimeCalculation
|
||||
class HighLevelException(cause: Throwable?) : Exception(cause)
|
||||
@CompileTimeCalculation
|
||||
class MidLevelException(cause: Throwable?) : Exception(cause)
|
||||
@CompileTimeCalculation
|
||||
class LowLevelException : Exception()
|
||||
|
||||
@CompileTimeCalculation
|
||||
class Junk {
|
||||
public fun a(): Nothing {
|
||||
try {
|
||||
b()
|
||||
} catch (e: MidLevelException) {
|
||||
throw HighLevelException(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun b(): Nothing = c()
|
||||
|
||||
private fun c(): Nothing {
|
||||
try {
|
||||
d()
|
||||
} catch (e: LowLevelException) {
|
||||
throw MidLevelException(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun d(): Nothing = e()
|
||||
|
||||
private fun e(): Nothing = throw LowLevelException()
|
||||
}
|
||||
|
||||
const val exceptionWithCause = Junk().a().<!WAS_NOT_EVALUATED: `
|
||||
Exception HighLevelException: MidLevelException: LowLevelException
|
||||
at ExceptionWithCauseKt.Junk.a(exceptionWithCause.kt:15)
|
||||
at ExceptionWithCauseKt.<clinit>(exceptionWithCause.kt:34)
|
||||
Caused by: MidLevelException: LowLevelException
|
||||
at ExceptionWithCauseKt.Junk.c(exceptionWithCause.kt:25)
|
||||
at ExceptionWithCauseKt.Junk.b(exceptionWithCause.kt:19)
|
||||
at ExceptionWithCauseKt.Junk.a(exceptionWithCause.kt:13)
|
||||
at ExceptionWithCauseKt.<clinit>(exceptionWithCause.kt:34)
|
||||
Caused by: LowLevelException
|
||||
at ExceptionWithCauseKt.Junk.e(exceptionWithCause.kt:31)
|
||||
at ExceptionWithCauseKt.Junk.d(exceptionWithCause.kt:29)
|
||||
at ExceptionWithCauseKt.Junk.c(exceptionWithCause.kt:23)
|
||||
at ExceptionWithCauseKt.Junk.b(exceptionWithCause.kt:19)
|
||||
at ExceptionWithCauseKt.Junk.a(exceptionWithCause.kt:13)
|
||||
at ExceptionWithCauseKt.<clinit>(exceptionWithCause.kt:34)`!>toString()<!>
|
||||
@@ -0,0 +1,22 @@
|
||||
import kotlin.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getArrayElement(array: IntArray, index: Int): Int {
|
||||
try {
|
||||
return array[index]
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
throw IllegalArgumentException("Index must be less than array size and greater than zero", e)
|
||||
}
|
||||
}
|
||||
|
||||
const val a = <!EVALUATED: `-1`!>try {
|
||||
getArrayElement(intArrayOf(1, 2, 3), -1).let { "Element at given index is " + it }
|
||||
} catch (e: Exception) {
|
||||
e.cause?.message ?: "Exception without message"
|
||||
}<!>
|
||||
|
||||
const val b = <!EVALUATED: `Element at given index is 1`!>try {
|
||||
getArrayElement(intArrayOf(1, 2, 3), 0).let { "Element at given index is " + it }
|
||||
} catch (e: Exception) {
|
||||
e.cause?.message ?: "Exception without message"
|
||||
}<!>
|
||||
@@ -0,0 +1,20 @@
|
||||
// FILE: main.kt
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun callToOtherFile(mustThrowException: Boolean, message: String): Int {
|
||||
if (mustThrowException) throwException(message)
|
||||
return 0
|
||||
}
|
||||
|
||||
const val a = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.Exception: Exception from file1.kt
|
||||
at File1Kt.throwException(file1.kt:19)
|
||||
at MainKt.callToOtherFile(main.kt:5)
|
||||
at MainKt.<clinit>(main.kt:9)`!>callToOtherFile(true, "Exception from file1.kt")<!>
|
||||
|
||||
// FILE: file1.kt
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun throwException(message: String) {
|
||||
throw Exception(message)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
@CompileTimeCalculation
|
||||
class A
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun notNullAssertion(value: Int?): String {
|
||||
return try {
|
||||
value!!
|
||||
"Value isn't null"
|
||||
} catch (e: NullPointerException) {
|
||||
"Value is null"
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun notNullAssertionForObject(value: A?): String {
|
||||
return try {
|
||||
value!!
|
||||
"Value isn't null"
|
||||
} catch (e: NullPointerException) {
|
||||
"Value is null"
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun notNullAssertionForSomeWrapper(value: StringBuilder?): String {
|
||||
return try {
|
||||
value!!.toString()
|
||||
} catch (e: NullPointerException) {
|
||||
"Value is null"
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun notNullLambda(lambda: (() -> String)?): String {
|
||||
return when {
|
||||
lambda != null -> lambda()
|
||||
else -> "Lambda is null"
|
||||
}
|
||||
}
|
||||
|
||||
const val a1 = <!EVALUATED: `Value isn't null`!>notNullAssertion(1)<!>
|
||||
const val a2 = <!EVALUATED: `Value is null`!>notNullAssertion(null)<!>
|
||||
const val b1 = <!EVALUATED: `Value isn't null`!>notNullAssertionForObject(A())<!>
|
||||
const val b2 = <!EVALUATED: `Value is null`!>notNullAssertionForObject(null)<!>
|
||||
const val c1 = <!EVALUATED: `Some text`!>notNullAssertionForSomeWrapper(StringBuilder("Some text"))<!>
|
||||
const val c2 = <!EVALUATED: `Value is null`!>notNullAssertionForSomeWrapper(null)<!>
|
||||
const val d1 = <!EVALUATED: `Not null lambda`!>notNullLambda { "Not null lambda" }<!>
|
||||
const val d2 = <!EVALUATED: `Lambda is null`!>notNullLambda(null)<!>
|
||||
@@ -0,0 +1,22 @@
|
||||
@CompileTimeCalculation
|
||||
fun foo(i: Int): Int = foo(i + 1)
|
||||
const val overflow = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.StackOverflowError
|
||||
at StackOverflowKt.foo(stackOverflow.kt:1)
|
||||
at StackOverflowKt.foo(stackOverflow.kt:2)
|
||||
at StackOverflowKt.foo(stackOverflow.kt:2)
|
||||
at StackOverflowKt.foo(stackOverflow.kt:2)
|
||||
at StackOverflowKt.foo(stackOverflow.kt:2)
|
||||
at StackOverflowKt.foo(stackOverflow.kt:2)
|
||||
at StackOverflowKt.foo(stackOverflow.kt:2)
|
||||
at StackOverflowKt.foo(stackOverflow.kt:2)
|
||||
at StackOverflowKt.foo(stackOverflow.kt:2)
|
||||
at StackOverflowKt.foo(stackOverflow.kt:2)
|
||||
...`!>foo(0)<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun withPossibleOverflow(x: Int): Int {
|
||||
if (x == 0) return 0
|
||||
return withPossibleOverflow(x - 1) + 1
|
||||
}
|
||||
const val notOverflow = <!EVALUATED: `5000`!>withPossibleOverflow(5_000)<!>
|
||||
@@ -0,0 +1,27 @@
|
||||
@CompileTimeCalculation
|
||||
fun divide(a: Int, b: Int) = a / b
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun echo(a : Int, b: Int) = divide(a, b)
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getLengthOrThrowException(str: String?): Int {
|
||||
try {
|
||||
return str!!.length
|
||||
} catch (e: NullPointerException) {
|
||||
throw UnsupportedOperationException(e)
|
||||
}
|
||||
}
|
||||
|
||||
const val a = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.ArithmeticException: / by zero
|
||||
at StackTraceKt.divide(stackTrace.kt:2)
|
||||
at StackTraceKt.echo(stackTrace.kt:5)
|
||||
at StackTraceKt.<clinit>(stackTrace.kt:16)`!>echo(1, 0)<!>
|
||||
const val b = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.UnsupportedOperationException: java.lang.NullPointerException
|
||||
at StackTraceKt.getLengthOrThrowException(stackTrace.kt:12)
|
||||
at StackTraceKt.<clinit>(stackTrace.kt:17)
|
||||
Caused by: java.lang.NullPointerException
|
||||
at StackTraceKt.getLengthOrThrowException(stackTrace.kt:10)
|
||||
at StackTraceKt.<clinit>(stackTrace.kt:17)`!>getLengthOrThrowException(null)<!>
|
||||
@@ -0,0 +1,215 @@
|
||||
@CompileTimeCalculation
|
||||
fun tryFinally(initValue: Int): Int {
|
||||
var x = initValue
|
||||
try {
|
||||
return x
|
||||
} finally {
|
||||
x = x + 1 // result is never used
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun tryFinally2(): String {
|
||||
var str: String = ""
|
||||
try {
|
||||
str += "Inside try block; "
|
||||
} finally {
|
||||
str += "Inside finally; "
|
||||
}
|
||||
str += "Outside try; "
|
||||
return str
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun outerReturnTryFinally(n: Int): Int {
|
||||
return try {
|
||||
n
|
||||
} finally {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun exceptionInFinally(divideBy: Int): Int {
|
||||
return try {
|
||||
0
|
||||
} finally {
|
||||
1 / divideBy
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun tryCatchFinally(): Int {
|
||||
try {
|
||||
throw IllegalArgumentException("In try")
|
||||
} catch (e: IllegalArgumentException) {
|
||||
throw IllegalArgumentException("In catch")
|
||||
} finally {
|
||||
throw IllegalArgumentException("In finally")
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun returnTryFinally(): String {
|
||||
return try { "OK" } finally { "NOT OK" } // result from finally is never used
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun tryCatchReturnFinally(divideBy: Int): Int {
|
||||
var y = 0
|
||||
try {
|
||||
1 / divideBy
|
||||
} catch (e: ArithmeticException) {
|
||||
return y
|
||||
} finally {
|
||||
y++
|
||||
}
|
||||
|
||||
return y
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun tryFinallyContinue(): Int {
|
||||
var y = 0
|
||||
while (y < 10) {
|
||||
try {
|
||||
continue
|
||||
} finally {
|
||||
y++
|
||||
}
|
||||
|
||||
throw IllegalStateException("\"continue\" must drop remaining frame")
|
||||
}
|
||||
|
||||
return y
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun tryFinallyBreak(): Int {
|
||||
var y = 0
|
||||
while (y < 10) {
|
||||
try {
|
||||
break
|
||||
} finally {
|
||||
y++
|
||||
}
|
||||
}
|
||||
|
||||
return y
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun tryCatchFinallyContinue(divideBy: Int): Int {
|
||||
var y = 0
|
||||
while (y < 10) {
|
||||
try {
|
||||
1 / divideBy
|
||||
} catch (e: ArithmeticException) {
|
||||
continue
|
||||
} finally {
|
||||
y++
|
||||
}
|
||||
|
||||
throw IllegalStateException("\"continue\" must drop remaining frame")
|
||||
}
|
||||
|
||||
return y
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun innerTryFinally(n: Int): Int {
|
||||
try {
|
||||
try {
|
||||
return 1
|
||||
} finally {
|
||||
n + 1
|
||||
}
|
||||
return 2
|
||||
} finally {
|
||||
n + 10
|
||||
}
|
||||
return 3
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun innerTryFinallyReturn(n: Int): Int {
|
||||
//return n / 0
|
||||
try {
|
||||
try {
|
||||
return 1
|
||||
} finally {
|
||||
n + 1
|
||||
}
|
||||
return 2
|
||||
} finally {
|
||||
return n + 10
|
||||
}
|
||||
return 3
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun tryCatch(n: Int): Int {
|
||||
return try {
|
||||
delete(n)
|
||||
} catch (e: ArithmeticException) {
|
||||
-1
|
||||
} finally {
|
||||
-2
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun delete(n: Int): Int {
|
||||
return try {
|
||||
1 / n
|
||||
} catch (e: NullPointerException) {
|
||||
-1
|
||||
} finally {
|
||||
-2
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun tryTryFinally(): Int {
|
||||
val zero = 0
|
||||
val nullable: Int? = null
|
||||
try {
|
||||
try {
|
||||
1 / zero
|
||||
} finally {
|
||||
nullable!!
|
||||
}
|
||||
} catch (e: NullPointerException) {
|
||||
return -1
|
||||
} finally {
|
||||
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
const val a1 = <!EVALUATED: `0`!>tryFinally(0)<!>
|
||||
const val a2 = <!EVALUATED: `10`!>tryFinally(10)<!>
|
||||
//const val a3 = outerReturnTryFinally(10) TODO -> `10`
|
||||
const val b1 = <!EVALUATED: `Inside try block; Inside finally; Outside try; `!>tryFinally2()<!>
|
||||
const val c1 = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.IllegalArgumentException: In finally
|
||||
at TryFinallyKt.tryCatchFinally(tryFinally.kt:48)
|
||||
at TryFinallyKt.<clinit>(tryFinally.kt:196)`!>tryCatchFinally()<!>
|
||||
const val c2 = <!EVALUATED: `0`!>exceptionInFinally(10)<!>
|
||||
const val c3 = <!WAS_NOT_EVALUATED: `
|
||||
Exception java.lang.ArithmeticException: / by zero
|
||||
at TryFinallyKt.exceptionInFinally(tryFinally.kt:37)
|
||||
at TryFinallyKt.<clinit>(tryFinally.kt:198)`!>exceptionInFinally(0)<!>
|
||||
//const val d1 = returnTryFinally() TODO -> `OK`
|
||||
const val d2 = <!EVALUATED: `1`!>tryCatchReturnFinally(10)<!>
|
||||
const val d3 = <!EVALUATED: `0`!>tryCatchReturnFinally(0)<!>
|
||||
const val e1 = <!EVALUATED: `10`!>tryFinallyContinue()<!>
|
||||
const val e2 = <!EVALUATED: `1`!>tryFinallyBreak()<!>
|
||||
const val e3 = <!EVALUATED: `10`!>tryCatchFinallyContinue(0)<!>
|
||||
//const val f1 = innerTryFinally(10) TODO -> `1`
|
||||
const val f2 = <!EVALUATED: `20`!>innerTryFinallyReturn(10)<!>
|
||||
//const val g1 = tryCatch(10) TODO -> `0`
|
||||
//const val g2 = tryCatch(0) TODO -> `-1`
|
||||
//const val h1 = tryTryFinally() TODO -> `-1`
|
||||
@@ -0,0 +1,19 @@
|
||||
@CompileTimeCalculation
|
||||
fun Int.get(): Int {
|
||||
return this
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
class A(val length: Int) {
|
||||
fun String.hasRightLength(): Boolean {
|
||||
return this@hasRightLength.length == this@A.length
|
||||
}
|
||||
|
||||
fun check(string: String): Boolean {
|
||||
return string.hasRightLength()
|
||||
}
|
||||
}
|
||||
|
||||
const val simple = 1.<!EVALUATED: `1`!>get()<!>
|
||||
const val right = A(3).<!EVALUATED: `true`!>check("123")<!>
|
||||
const val wrong = A(2).<!EVALUATED: `false`!>check("123")<!>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
@CompileTimeCalculation
|
||||
fun fib(n: Int) : Int {
|
||||
if (n <= 1) return n
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
}
|
||||
|
||||
const val n2 = <!EVALUATED: `1`!>fib(2)<!>
|
||||
const val n10 = <!EVALUATED: `55`!>fib(10)<!>
|
||||
const val n18 = <!EVALUATED: `2584`!>fib(18)<!>
|
||||
@@ -0,0 +1,7 @@
|
||||
import kotlin.collections.*
|
||||
import kotlin.sequences.*
|
||||
|
||||
const val a = intArrayOf(1, 2, 3).<!EVALUATED: `true`!>contains(1)<!>
|
||||
const val b = intArrayOf(1, 2, 3).<!EVALUATED: `false`!>contains(4)<!>
|
||||
const val c = arrayOf(1, "2", 3.0).<!EVALUATED: `true`!>contains("2")<!>
|
||||
const val d = sequenceOf(1, 2, 3).<!EVALUATED: `true`!>contains(2)<!>
|
||||
@@ -0,0 +1,9 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
import kotlin.text.*
|
||||
|
||||
const val a = listOf(1, 2, 3).<!EVALUATED: `2`!>elementAtOrElse(1) { -1 }<!>
|
||||
const val b = listOf(1, 2, 3).<!EVALUATED: `-1`!>elementAtOrElse(4) { -1 }<!>
|
||||
const val c = uintArrayOf(1u, 2u, 3u, 4u).<!EVALUATED: `3`!>elementAtOrElse(2) { 0u }<!>
|
||||
const val d = "abcd".<!EVALUATED: `c`!>elementAtOrElse(2) { '0' }<!>
|
||||
const val e = "abcd".<!EVALUATED: `0`!>elementAtOrElse(4) { '0' }<!>
|
||||
@@ -0,0 +1,11 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
import kotlin.text.*
|
||||
|
||||
const val a = "abcs".<!EVALUATED: `a`!>first()<!>
|
||||
const val b = UIntArray(3) { it.toUInt() }.<!EVALUATED: `0`!>first()<!>
|
||||
const val c = <!EVALUATED: `1`!>listOf(1, "2", 3.0).first() as Int<!>
|
||||
const val d = listOf<Int>().<!WAS_NOT_EVALUATED: `
|
||||
Exception java.util.NoSuchElementException: List is empty.
|
||||
at CollectionsKt.kotlin.collections.first(Collections.kt:88)
|
||||
at FirstKt.<clinit>(first.kt:8)`!>first()<!>
|
||||
@@ -0,0 +1,5 @@
|
||||
import kotlin.collections.*
|
||||
import kotlin.sequences.*
|
||||
|
||||
const val a = listOf(1, 2, 3).<!EVALUATED: `1, 2, 3`!>joinToString()<!>
|
||||
const val b = sequenceOf(-1, -2, -3).<!EVALUATED: `-1.-2.-3`!>joinToString(separator = ".")<!>
|
||||
@@ -0,0 +1,16 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
import kotlin.text.*
|
||||
import kotlin.sequences.*
|
||||
|
||||
const val zeroElementIntArrayToList = intArrayOf().toList().<!EVALUATED: `0`!>size<!>
|
||||
const val singleElementIntArrayToList = intArrayOf(1).toList().<!EVALUATED: `1`!>size<!>
|
||||
const val intArrayToList = intArrayOf(1, 2, 3).toList().<!EVALUATED: `3`!>size<!>
|
||||
const val customArrayToList = <!EVALUATED: `Some other value`!>arrayOf(1, "2", 3.0, "Some other value").toList()[3] as String<!>
|
||||
|
||||
const val listFromSet = setOf(1, 2, 2, 3, 3).toList().<!EVALUATED: `1, 2, 3`!>joinToString()<!>
|
||||
const val listFromIterable = mapOf(1 to "One", 2 to "Two", 3 to "Three").entries.toList().<!EVALUATED: `1=One, 2=Two, 3=Three`!>joinToString()<!>
|
||||
|
||||
const val stringToList = "String".toList().<!EVALUATED: `S, t, r, i, n, g`!>joinToString()<!>
|
||||
|
||||
const val sequenceToList = sequenceOf(3, 2, 1).toList().<!EVALUATED: `3, 2, 1`!>joinToString()<!>
|
||||
@@ -0,0 +1,5 @@
|
||||
import kotlin.text.*
|
||||
|
||||
const val trimmed = " 1 ".<!EVALUATED: `1`!>trim()<!>
|
||||
const val trimmedWithPredicate = (" 2 " as CharSequence).trim { it.isWhitespace() }.<!EVALUATED: `2`!>toString()<!>
|
||||
const val charSequenceTrim = (" 3 " as CharSequence).trim().<!EVALUATED: `3`!>toString()<!>
|
||||
@@ -0,0 +1,11 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <F, S> listOfPairs(): String {
|
||||
val list = mutableListOf<Pair<F, S>>()
|
||||
list.add((1 to 100) as Pair<F, S>)
|
||||
list.add(("2" to "200") as Pair<F, S>)
|
||||
return "List size is: ${list.size}; first is Int: ${list[0].first is Int}; second is String: ${list[1].first is String}"
|
||||
}
|
||||
const val listOfPairsSize = <!EVALUATED: `List size is: 2; first is Int: true; second is String: true`!>listOfPairs<Int, Int>()<!>
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("ArraysKt")
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
public operator fun <T> Array<out T>.contains(element: T): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun ByteArray.contains(element: Byte): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun ShortArray.contains(element: Short): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun IntArray.contains(element: Int): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun LongArray.contains(element: Long): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun BooleanArray.contains(element: Boolean): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
public operator fun CharArray.contains(element: Char): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
|
||||
public fun <T> Array<out T>.indexOf(element: T): Int {
|
||||
if (element == null) {
|
||||
for (index in indices) {
|
||||
if (this[index] == null) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun ByteArray.indexOf(element: Byte): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun ShortArray.indexOf(element: Short): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun IntArray.indexOf(element: Int): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun LongArray.indexOf(element: Long): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun BooleanArray.indexOf(element: Boolean): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public fun CharArray.indexOf(element: Char): Int {
|
||||
for (index in indices) {
|
||||
if (element == this[index]) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
public actual fun <T> Array<out T>.asList(): List<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun ByteArray.asList(): List<Byte> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun ShortArray.asList(): List<Short> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun IntArray.asList(): List<Int> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun LongArray.asList(): List<Long> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun FloatArray.asList(): List<Float> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun DoubleArray.asList(): List<Double> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun BooleanArray.asList(): List<Boolean> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public actual fun CharArray.asList(): List<Char> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public val <T> Array<out T>.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val ByteArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val ShortArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val IntArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val LongArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val FloatArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val DoubleArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val BooleanArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
public val CharArray.indices: IntRange
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
public inline fun <T> Array<out T>.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
}
|
||||
|
||||
public val <T> Array<out T>.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val ByteArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val ShortArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val IntArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val LongArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val FloatArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val DoubleArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val BooleanArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
public val CharArray.lastIndex: Int
|
||||
get() = size - 1
|
||||
|
||||
public fun ByteArray.first(): Int {
|
||||
if (isEmpty()) throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
public fun ShortArray.first(): Int {
|
||||
if (isEmpty()) throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
public fun IntArray.first(): Int {
|
||||
if (isEmpty()) throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
public fun LongArray.first(): Int {
|
||||
if (isEmpty()) throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
public inline fun ByteArray.isEmpty(): Boolean = size == 0
|
||||
public inline fun ShortArray.isEmpty(): Boolean = size == 0
|
||||
public inline fun IntArray.isEmpty(): Boolean = size == 0
|
||||
public inline fun LongArray.isEmpty(): Boolean = size == 0
|
||||
|
||||
public fun <T> Array<out T>.toList(): List<T> {
|
||||
return when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(this[0])
|
||||
else -> this.toMutableList()
|
||||
}
|
||||
}
|
||||
public fun IntArray.toList(): List<Int> {
|
||||
return when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(this[0])
|
||||
else -> this.toMutableList()
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> Array<out T>.toMutableList(): MutableList<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
public fun IntArray.toMutableList(): MutableList<Int> {
|
||||
val list = ArrayList<Int>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
|
||||
public fun <T, C : MutableCollection<in T>> Array<out T>.toCollection(destination: C): C {
|
||||
for (item in this) {
|
||||
destination.add(item)
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
public fun <T> Array<out T>.toSet(): Set<T> {
|
||||
return when (size) {
|
||||
0 -> emptySet()
|
||||
1 -> setOf(this[0])
|
||||
else -> toCollection(LinkedHashSet<T>(mapCapacity(size)))
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> Array<out T>.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
public fun <T, A : Appendable> Array<out T>.joinTo(buffer: A, separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): A {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
buffer.appendElement(element, transform)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
return buffer
|
||||
}
|
||||
|
||||
private fun <T> Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) {
|
||||
when {
|
||||
transform != null -> append(transform(element))
|
||||
element is CharSequence? -> append(element)
|
||||
element is Char -> append(element)
|
||||
else -> append(element.toString())
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> Array<out T>.asSequence(): Sequence<T> {
|
||||
if (isEmpty()) return emptySequence()
|
||||
return Sequence { this.iterator() }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("CharsKt")
|
||||
|
||||
package kotlin.text
|
||||
|
||||
public actual fun Char.isWhitespace(): Boolean = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
@@ -0,0 +1,176 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("CollectionsKt")
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
internal object EmptyIterator : ListIterator<Nothing> {
|
||||
override fun hasNext(): Boolean = false
|
||||
override fun hasPrevious(): Boolean = false
|
||||
override fun nextIndex(): Int = 0
|
||||
override fun previousIndex(): Int = -1
|
||||
override fun next(): Nothing = throw NoSuchElementException()
|
||||
override fun previous(): Nothing = throw NoSuchElementException()
|
||||
}
|
||||
|
||||
internal object EmptyList : List<Nothing>, Serializable, RandomAccess {
|
||||
private const val serialVersionUID: Long = -7390468764508069838L
|
||||
|
||||
override fun equals(other: Any?): Boolean = other is List<*> && other.isEmpty()
|
||||
override fun hashCode(): Int = 1
|
||||
override fun toString(): String = "[]"
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
override fun contains(element: Nothing): Boolean = false
|
||||
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
|
||||
|
||||
override fun get(index: Int): Nothing = throw IndexOutOfBoundsException("Empty list doesn't contain element at index $index.")
|
||||
override fun indexOf(element: Nothing): Int = -1
|
||||
override fun lastIndexOf(element: Nothing): Int = -1
|
||||
|
||||
override fun iterator(): Iterator<Nothing> = EmptyIterator
|
||||
override fun listIterator(): ListIterator<Nothing> = EmptyIterator
|
||||
override fun listIterator(index: Int): ListIterator<Nothing> {
|
||||
if (index != 0) throw IndexOutOfBoundsException("Index: $index")
|
||||
return EmptyIterator
|
||||
}
|
||||
|
||||
override fun subList(fromIndex: Int, toIndex: Int): List<Nothing> {
|
||||
if (fromIndex == 0 && toIndex == 0) return this
|
||||
throw IndexOutOfBoundsException("fromIndex: $fromIndex, toIndex: $toIndex")
|
||||
}
|
||||
|
||||
private fun readResolve(): Any = EmptyList
|
||||
}
|
||||
|
||||
public fun <T> emptyList(): List<T> = EmptyList
|
||||
|
||||
public fun <T> listOf(vararg elements: T): List<T> = if (elements.size > 0) elements.asList() else emptyList()
|
||||
|
||||
public inline fun <T> listOf(): List<T> = emptyList()
|
||||
|
||||
public inline fun <T> mutableListOf(): MutableList<T> = ArrayList()
|
||||
|
||||
public inline fun <T> arrayListOf(): ArrayList<T> = ArrayList()
|
||||
|
||||
public fun <T> mutableListOf(vararg elements: T): MutableList<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public fun <T> arrayListOf(vararg elements: T): ArrayList<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public fun <T : Any> listOfNotNull(element: T?): List<T> = if (element != null) listOf(element) else emptyList()
|
||||
|
||||
public inline fun <T> List(size: Int, init: (index: Int) -> T): List<T> = MutableList(size, init)
|
||||
|
||||
public inline fun <T> MutableList(size: Int, init: (index: Int) -> T): MutableList<T> {
|
||||
val list = ArrayList<T>(size)
|
||||
repeat(size) { index -> list.add(init(index)) }
|
||||
return list
|
||||
}
|
||||
|
||||
public val Collection<*>.indices: IntRange
|
||||
get() = 0..size - 1
|
||||
|
||||
public val <T> List<T>.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
|
||||
public inline fun <T> Collection<T>.isNotEmpty(): Boolean = !isEmpty()
|
||||
|
||||
public inline fun <T> List<T>.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T {
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
|
||||
}
|
||||
|
||||
public fun <T> List<T>.first(): T {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("List is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
public fun <T> Iterable<T>.single(): T {
|
||||
when (this) {
|
||||
is List -> return this.single()
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
val single = iterator.next()
|
||||
if (iterator.hasNext())
|
||||
throw IllegalArgumentException("Collection has more than one element.")
|
||||
return single
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> List<T>.single(): T {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("List is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("List has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> Iterable<T>.toList(): List<T> {
|
||||
if (this is Collection) {
|
||||
return when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(if (this is List) get(0) else iterator().next())
|
||||
else -> this.toMutableList()
|
||||
}
|
||||
}
|
||||
return this.toMutableList().optimizeReadOnlyList()
|
||||
}
|
||||
|
||||
public fun <T> Iterable<T>.toMutableList(): MutableList<T> {
|
||||
if (this is Collection<T>)
|
||||
return this.toMutableList()
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
public fun <T> Collection<T>.toMutableList(): MutableList<T> {
|
||||
return ArrayList(this)
|
||||
}
|
||||
|
||||
public fun <T, C : MutableCollection<in T>> Iterable<T>.toCollection(destination: C): C {
|
||||
for (item in this) {
|
||||
destination.add(item)
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
internal fun <T> List<T>.optimizeReadOnlyList() = when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(this[0])
|
||||
else -> this
|
||||
}
|
||||
|
||||
public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
|
||||
if (this is Collection && isEmpty()) return true
|
||||
for (element in this) if (!predicate(element)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
public fun <T, A : Appendable> Iterable<T>.joinTo(buffer: A, separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): A {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
buffer.appendElement(element, transform)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
return buffer
|
||||
}
|
||||
|
||||
private fun <T> Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) {
|
||||
when {
|
||||
transform != null -> append(transform(element))
|
||||
element is CharSequence? -> append(element)
|
||||
element is Char -> append(element)
|
||||
else -> append(element.toString())
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> Iterable<T>.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("MapsKt")
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
import kotlin.sequences.*
|
||||
|
||||
private object EmptyMap : Map<Any?, Nothing>, Serializable {
|
||||
private const val serialVersionUID: Long = 8246714829545688274
|
||||
|
||||
override fun equals(other: Any?): Boolean = other is Map<*, *> && other.isEmpty()
|
||||
override fun hashCode(): Int = 0
|
||||
override fun toString(): String = "{}"
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
|
||||
override fun containsKey(key: Any?): Boolean = false
|
||||
override fun containsValue(value: Nothing): Boolean = false
|
||||
override fun get(key: Any?): Nothing? = null
|
||||
override val entries: Set<Map.Entry<Any?, Nothing>> get() = EmptySet
|
||||
override val keys: Set<Any?> get() = EmptySet
|
||||
override val values: Collection<Nothing> get() = EmptyList
|
||||
|
||||
private fun readResolve(): Any = EmptyMap
|
||||
}
|
||||
|
||||
public fun <K, V> emptyMap(): Map<K, V> = @Suppress("UNCHECKED_CAST") (EmptyMap as Map<K, V>)
|
||||
|
||||
public fun <K, V> mapOf(vararg pairs: Pair<K, V>): Map<K, V> =
|
||||
if (pairs.size > 0) pairs.toMap(LinkedHashMap(mapCapacity(pairs.size))) else emptyMap()
|
||||
|
||||
public inline fun <K, V> mapOf(): Map<K, V> = emptyMap()
|
||||
|
||||
public inline fun <K, V> mutableMapOf(): MutableMap<K, V> = LinkedHashMap()
|
||||
|
||||
public fun <K, V> mutableMapOf(vararg pairs: Pair<K, V>): MutableMap<K, V> =
|
||||
LinkedHashMap<K, V>(mapCapacity(pairs.size)).apply { putAll(pairs) }
|
||||
|
||||
public inline fun <K, V> hashMapOf(): HashMap<K, V> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public fun <K, V> hashMapOf(vararg pairs: Pair<K, V>): HashMap<K, V> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public inline fun <K, V> linkedMapOf(): LinkedHashMap<K, V> = LinkedHashMap<K, V>()
|
||||
|
||||
internal fun mapCapacity(expectedSize: Int): Int = when {
|
||||
// We are not coercing the value to a valid one and not throwing an exception. It is up to the caller to
|
||||
// properly handle negative values.
|
||||
expectedSize < 0 -> expectedSize
|
||||
expectedSize < 3 -> expectedSize + 1
|
||||
expectedSize < 1 shl (Int.SIZE_BITS - 2) -> ((expectedSize / 0.75F) + 1.0F).toInt()
|
||||
// any large value
|
||||
else -> Int.MAX_VALUE
|
||||
}
|
||||
|
||||
public inline operator fun <K, V> Map<out K, V>.contains(key: K): Boolean = containsKey(key)
|
||||
|
||||
public inline operator fun <K, V> Map<out K, V>.get(key: K): V? = (this as Map<K, V>).get(key)
|
||||
|
||||
public inline operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): Unit {
|
||||
put(key, value)
|
||||
}
|
||||
|
||||
public inline fun <K> Map<out K, *>.containsKey(key: K): Boolean = (this as Map<K, *>).containsKey(key)
|
||||
|
||||
public inline fun <K, V> Map<K, V>.containsValue(value: V): Boolean = this.containsValue(value)
|
||||
|
||||
public inline fun <K, V> MutableMap<out K, V>.remove(key: K): V? = (this as MutableMap<K, V>).remove(key)
|
||||
|
||||
public inline operator fun <K, V> Map.Entry<K, V>.component1(): K = key
|
||||
|
||||
public inline operator fun <K, V> Map.Entry<K, V>.component2(): V = value
|
||||
|
||||
public inline fun <K, V> Map.Entry<K, V>.toPair(): Pair<K, V> = Pair(key, value)
|
||||
|
||||
public inline operator fun <K, V> Map<out K, V>.iterator(): Iterator<Map.Entry<K, V>> = entries.iterator()
|
||||
|
||||
public fun <K, V> MutableMap<in K, in V>.putAll(pairs: Array<out Pair<K, V>>): Unit {
|
||||
for ((key, value) in pairs) {
|
||||
put(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
public fun <K, V> MutableMap<in K, in V>.putAll(pairs: Iterable<Pair<K, V>>): Unit {
|
||||
for ((key, value) in pairs) {
|
||||
put(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
public fun <K, V> MutableMap<in K, in V>.putAll(pairs: Sequence<Pair<K, V>>): Unit {
|
||||
for ((key, value) in pairs) {
|
||||
put(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
public fun <K, V> Iterable<Pair<K, V>>.toMap(): Map<K, V> {
|
||||
if (this is Collection) {
|
||||
return when (size) {
|
||||
0 -> emptyMap()
|
||||
1 -> mapOf(if (this is List) this[0] else iterator().next())
|
||||
else -> toMap(LinkedHashMap<K, V>(mapCapacity(size)))
|
||||
}
|
||||
}
|
||||
return toMap(LinkedHashMap<K, V>()).optimizeReadOnlyMap()
|
||||
}
|
||||
|
||||
public fun <K, V, M : MutableMap<in K, in V>> Iterable<Pair<K, V>>.toMap(destination: M): M = destination.apply { putAll(this@toMap) }
|
||||
|
||||
public fun <K, V> Array<out Pair<K, V>>.toMap(): Map<K, V> = when (size) {
|
||||
0 -> emptyMap()
|
||||
1 -> mapOf(this[0])
|
||||
else -> toMap(LinkedHashMap<K, V>(mapCapacity(size)))
|
||||
}
|
||||
|
||||
public fun <K, V, M : MutableMap<in K, in V>> Array<out Pair<K, V>>.toMap(destination: M): M = destination.apply { putAll(this@toMap) }
|
||||
|
||||
public fun <K, V> Sequence<Pair<K, V>>.toMap(): Map<K, V> = toMap(LinkedHashMap<K, V>()).optimizeReadOnlyMap()
|
||||
|
||||
public fun <K, V, M : MutableMap<in K, in V>> Sequence<Pair<K, V>>.toMap(destination: M): M = destination.apply { putAll(this@toMap) }
|
||||
|
||||
internal fun <K, V> Map<K, V>.optimizeReadOnlyMap() = when (size) {
|
||||
0 -> emptyMap()
|
||||
1 -> this // toSingletonMapOrSelf()
|
||||
else -> this
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("RangesKt")
|
||||
|
||||
package kotlin.ranges
|
||||
|
||||
public infix fun Int.until(to: Byte): IntRange {
|
||||
return this .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
public infix fun Long.until(to: Byte): LongRange {
|
||||
return this .. (to.toLong() - 1).toLong()
|
||||
}
|
||||
public infix fun Byte.until(to: Byte): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
public infix fun Short.until(to: Byte): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
|
||||
public infix fun Char.until(to: Char): CharRange {
|
||||
if (to <= '\u0000') return CharRange.EMPTY
|
||||
return this .. (to - 1).toChar()
|
||||
}
|
||||
|
||||
public infix fun Int.until(to: Int): IntRange {
|
||||
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
|
||||
return this .. (to - 1).toInt()
|
||||
}
|
||||
public infix fun Long.until(to: Int): LongRange {
|
||||
return this .. (to.toLong() - 1).toLong()
|
||||
}
|
||||
public infix fun Byte.until(to: Int): IntRange {
|
||||
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
|
||||
return this.toInt() .. (to - 1).toInt()
|
||||
}
|
||||
public infix fun Short.until(to: Int): IntRange {
|
||||
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
|
||||
return this.toInt() .. (to - 1).toInt()
|
||||
}
|
||||
|
||||
public infix fun Int.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this.toLong() .. (to - 1).toLong()
|
||||
}
|
||||
public infix fun Long.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this .. (to - 1).toLong()
|
||||
}
|
||||
public infix fun Byte.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this.toLong() .. (to - 1).toLong()
|
||||
}
|
||||
public infix fun Short.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this.toLong() .. (to - 1).toLong()
|
||||
}
|
||||
|
||||
public infix fun Int.until(to: Short): IntRange {
|
||||
return this .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
public infix fun Long.until(to: Short): LongRange {
|
||||
return this .. (to.toLong() - 1).toLong()
|
||||
}
|
||||
public infix fun Byte.until(to: Short): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
public infix fun Short.until(to: Short): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("SequencesKt")
|
||||
|
||||
package kotlin.sequences
|
||||
|
||||
public inline fun <T> Sequence(crossinline iterator: () -> Iterator<T>): Sequence<T> = object : Sequence<T> {
|
||||
override fun iterator(): Iterator<T> = iterator()
|
||||
}
|
||||
|
||||
public fun <T> Iterator<T>.asSequence(): Sequence<T> = Sequence { this }//.constrainOnce()
|
||||
|
||||
public fun <T> sequenceOf(vararg elements: T): Sequence<T> = if (elements.isEmpty()) emptySequence() else elements.asSequence()
|
||||
|
||||
public fun <T> emptySequence(): Sequence<T> = EmptySequence
|
||||
|
||||
private object EmptySequence : Sequence<Nothing>, DropTakeSequence<Nothing> {
|
||||
override fun iterator(): Iterator<Nothing> = EmptyIterator
|
||||
override fun drop(n: Int) = EmptySequence
|
||||
override fun take(n: Int) = EmptySequence
|
||||
}
|
||||
|
||||
public inline fun <T> Sequence<T>?.orEmpty(): Sequence<T> = this ?: emptySequence()
|
||||
|
||||
private class GeneratorSequence<T : Any>(private val getInitialValue: () -> T?, private val getNextValue: (T) -> T?) : Sequence<T> {
|
||||
override fun iterator(): Iterator<T> = object : Iterator<T> {
|
||||
var nextItem: T? = null
|
||||
var nextState: Int = -2 // -2 for initial unknown, -1 for next unknown, 0 for done, 1 for continue
|
||||
|
||||
private fun calcNext() {
|
||||
nextItem = if (nextState == -2) getInitialValue() else getNextValue(nextItem!!)
|
||||
nextState = if (nextItem == null) 0 else 1
|
||||
}
|
||||
|
||||
override fun next(): T {
|
||||
if (nextState < 0)
|
||||
calcNext()
|
||||
|
||||
if (nextState == 0)
|
||||
throw NoSuchElementException()
|
||||
val result = nextItem as T
|
||||
// Do not clean nextItem (to avoid keeping reference on yielded instance) -- need to keep state for getNextValue
|
||||
nextState = -1
|
||||
return result
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
if (nextState < 0)
|
||||
calcNext()
|
||||
return nextState == 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T : Any> generateSequence(nextFunction: () -> T?): Sequence<T> {
|
||||
return GeneratorSequence(nextFunction, { nextFunction() })//.constrainOnce()
|
||||
}
|
||||
|
||||
public fun <T : Any> generateSequence(seed: T?, nextFunction: (T) -> T?): Sequence<T> =
|
||||
if (seed == null)
|
||||
EmptySequence
|
||||
else
|
||||
GeneratorSequence({ seed }, nextFunction)
|
||||
|
||||
public fun <T : Any> generateSequence(seedFunction: () -> T?, nextFunction: (T) -> T?): Sequence<T> =
|
||||
GeneratorSequence(seedFunction, nextFunction)
|
||||
|
||||
public operator fun <T> Sequence<T>.contains(element: T): Boolean {
|
||||
return indexOf(element) >= 0
|
||||
}
|
||||
|
||||
public fun <T> Sequence<T>.indexOf(element: T): Int {
|
||||
var index = 0
|
||||
for (item in this) {
|
||||
checkIndexOverflow(index)
|
||||
if (element == item)
|
||||
return index
|
||||
index++
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
public fun <T> Sequence<T>.toList(): List<T> {
|
||||
return this.toMutableList().optimizeReadOnlyList()
|
||||
}
|
||||
|
||||
public fun <T> Sequence<T>.toMutableList(): MutableList<T> {
|
||||
return toCollection(ArrayList<T>())
|
||||
}
|
||||
|
||||
public fun <T, C : MutableCollection<in T>> Sequence<T>.toCollection(destination: C): C {
|
||||
for (item in this) {
|
||||
destination.add(item)
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
public fun <T> Sequence<T>.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String {
|
||||
return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString()
|
||||
}
|
||||
|
||||
public fun <T, A : Appendable> Sequence<T>.joinTo(buffer: A, separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): A {
|
||||
buffer.append(prefix)
|
||||
var count = 0
|
||||
for (element in this) {
|
||||
if (++count > 1) buffer.append(separator)
|
||||
if (limit < 0 || count <= limit) {
|
||||
buffer.appendElement(element, transform)
|
||||
} else break
|
||||
}
|
||||
if (limit >= 0 && count > limit) buffer.append(truncated)
|
||||
buffer.append(postfix)
|
||||
return buffer
|
||||
}
|
||||
|
||||
private fun <T> Appendable.appendElement(element: T, transform: ((T) -> CharSequence)?) {
|
||||
when {
|
||||
transform != null -> append(transform(element))
|
||||
element is CharSequence? -> append(element)
|
||||
element is Char -> append(element)
|
||||
else -> append(element.toString())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("SetsKt")
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
internal object EmptySet : Set<Nothing>, Serializable {
|
||||
private const val serialVersionUID: Long = 3406603774387020532
|
||||
|
||||
override fun equals(other: Any?): Boolean = other is Set<*> && other.isEmpty()
|
||||
override fun hashCode(): Int = 0
|
||||
override fun toString(): String = "[]"
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
override fun contains(element: Nothing): Boolean = false
|
||||
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
|
||||
|
||||
override fun iterator(): Iterator<Nothing> = EmptyIterator
|
||||
|
||||
private fun readResolve(): Any = EmptySet
|
||||
}
|
||||
|
||||
public fun <T> emptySet(): Set<T> = EmptySet
|
||||
|
||||
public fun <T> setOf(vararg elements: T): Set<T> = if (elements.size > 0) elements.toSet() else emptySet()
|
||||
|
||||
public inline fun <T> setOf(): Set<T> = emptySet()
|
||||
|
||||
public inline fun <T> mutableSetOf(): MutableSet<T> = LinkedHashSet()
|
||||
|
||||
public fun <T> mutableSetOf(vararg elements: T): MutableSet<T> = elements.toCollection(LinkedHashSet(mapCapacity(elements.size)))
|
||||
|
||||
public inline fun <T> hashSetOf(): HashSet<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
public fun <T> hashSetOf(vararg elements: T): HashSet<T> = kotlin.UnsupportedOperationException("This is intrinsic")
|
||||
|
||||
internal fun <T> Set<T>.optimizeReadOnlySet() = when (size) {
|
||||
0 -> emptySet()
|
||||
1 -> setOf(iterator().next())
|
||||
else -> this
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package kotlin
|
||||
|
||||
import kotlin.*
|
||||
|
||||
public inline fun <R> run(block: () -> R): R {
|
||||
return block()
|
||||
}
|
||||
|
||||
public inline fun <T, R> T.run(block: T.() -> R): R {
|
||||
return block()
|
||||
}
|
||||
|
||||
public inline fun <T, R> with(receiver: T, block: T.() -> R): R {
|
||||
return receiver.block()
|
||||
}
|
||||
|
||||
public inline fun <T> T.apply(block: T.() -> Unit): T {
|
||||
block()
|
||||
return this
|
||||
}
|
||||
|
||||
public inline fun <T> T.also(block: (T) -> Unit): T {
|
||||
block(this)
|
||||
return this
|
||||
}
|
||||
|
||||
public inline fun <T, R> T.let(block: (T) -> R): R {
|
||||
return block(this)
|
||||
}
|
||||
|
||||
public inline fun <T> T.takeIf(predicate: (T) -> Boolean): T? {
|
||||
return if (predicate(this)) this else null
|
||||
}
|
||||
|
||||
public inline fun <T> T.takeUnless(predicate: (T) -> Boolean): T? {
|
||||
return if (!predicate(this)) this else null
|
||||
}
|
||||
|
||||
public inline fun repeat(times: Int, action: (Int) -> Unit) {
|
||||
for (index in 0 until times) {
|
||||
action(index)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("StringsKt")
|
||||
|
||||
package kotlin.text
|
||||
|
||||
public inline fun CharSequence.trim(predicate: (Char) -> Boolean): CharSequence {
|
||||
var startIndex = 0
|
||||
var endIndex = length - 1
|
||||
var startFound = false
|
||||
|
||||
while (startIndex <= endIndex) {
|
||||
val index = if (!startFound) startIndex else endIndex
|
||||
val match = predicate(this[index])
|
||||
|
||||
if (!startFound) {
|
||||
if (!match)
|
||||
startFound = true
|
||||
else
|
||||
startIndex += 1
|
||||
} else {
|
||||
if (!match)
|
||||
break
|
||||
else
|
||||
endIndex -= 1
|
||||
}
|
||||
}
|
||||
|
||||
return subSequence(startIndex, endIndex + 1)
|
||||
}
|
||||
|
||||
public fun CharSequence.trim(): CharSequence = trim(Char::isWhitespace)
|
||||
|
||||
public inline fun String.trim(): String = (this as CharSequence).trim().toString()
|
||||
|
||||
public inline fun CharSequence.isEmpty(): Boolean = length == 0
|
||||
|
||||
public inline fun CharSequence.isNotEmpty(): Boolean = length > 0
|
||||
|
||||
public operator fun CharSequence.iterator(): CharIterator = object : CharIterator() {
|
||||
private var index = 0
|
||||
|
||||
public override fun nextChar(): Char = get(index++)
|
||||
|
||||
public override fun hasNext(): Boolean = index < length
|
||||
}
|
||||
|
||||
public fun CharSequence.first(): Char {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Char sequence is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
public val CharSequence.indices: IntRange
|
||||
get() = 0..length - 1
|
||||
|
||||
public val CharSequence.lastIndex: Int
|
||||
get() = this.length - 1
|
||||
|
||||
public inline fun CharSequence.substring(startIndex: Int, endIndex: Int = length): String = subSequence(startIndex, endIndex).toString()
|
||||
|
||||
public fun CharSequence.substring(range: IntRange): String = subSequence(range.start, range.endInclusive + 1).toString()
|
||||
|
||||
public inline fun CharSequence.elementAtOrElse(index: Int, defaultValue: (Int) -> Char): Char {
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
|
||||
}
|
||||
|
||||
public fun CharSequence.toList(): List<Char> {
|
||||
return when (length) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(this[0])
|
||||
else -> this.toMutableList()
|
||||
}
|
||||
}
|
||||
|
||||
public fun CharSequence.toMutableList(): MutableList<Char> {
|
||||
return toCollection(ArrayList<Char>(length))
|
||||
}
|
||||
|
||||
public fun <C : MutableCollection<in Char>> CharSequence.toCollection(destination: C): C {
|
||||
for (item in this) {
|
||||
destination.add(item)
|
||||
}
|
||||
return destination
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
@file:kotlin.jvm.JvmMultifileClass
|
||||
@file:kotlin.jvm.JvmName("UArraysKt")
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
public inline fun UIntArray.elementAtOrElse(index: Int, defaultValue: (Int) -> UInt): UInt {
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
|
||||
}
|
||||
|
||||
public inline val UIntArray.indices: IntRange
|
||||
get() = storage.indices
|
||||
public inline val ULongArray.indices: IntRange
|
||||
get() = storage.indices
|
||||
public inline val UByteArray.indices: IntRange
|
||||
get() = storage.indices
|
||||
public inline val UShortArray.indices: IntRange
|
||||
get() = storage.indices
|
||||
|
||||
public inline val UIntArray.lastIndex: Int
|
||||
get() = storage.lastIndex
|
||||
public inline val ULongArray.lastIndex: Int
|
||||
get() = storage.lastIndex
|
||||
public inline val UByteArray.lastIndex: Int
|
||||
get() = storage.lastIndex
|
||||
public inline val UShortArray.lastIndex: Int
|
||||
get() = storage.lastIndex
|
||||
|
||||
public inline fun UIntArray.first(): UInt {
|
||||
return storage.first().toUInt()
|
||||
}
|
||||
public inline fun ULongArray.first(): ULong {
|
||||
return storage.first().toULong()
|
||||
}
|
||||
public inline fun UByteArray.first(): UByte {
|
||||
return storage.first().toUByte()
|
||||
}
|
||||
public inline fun UShortArray.first(): UShort {
|
||||
return storage.first().toUShort()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package kotlin
|
||||
|
||||
public inline infix fun Byte.and(other: Byte): Byte = (this.toInt() and other.toInt()).toByte()
|
||||
public inline infix fun Byte.or(other: Byte): Byte = (this.toInt() or other.toInt()).toByte()
|
||||
public inline infix fun Byte.xor(other: Byte): Byte = (this.toInt() xor other.toInt()).toByte()
|
||||
public inline fun Byte.inv(): Byte = (this.toInt().inv()).toByte()
|
||||
|
||||
public inline infix fun Short.and(other: Short): Short = (this.toInt() and other.toInt()).toShort()
|
||||
public inline infix fun Short.or(other: Short): Short = (this.toInt() or other.toInt()).toShort()
|
||||
public inline infix fun Short.xor(other: Short): Short = (this.toInt() xor other.toInt()).toShort()
|
||||
public inline fun Short.inv(): Short = (this.toInt().inv()).toShort()
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package kotlin
|
||||
|
||||
public inline val Char.code: Int get() = this.toInt()
|
||||
|
||||
expect fun Double.isNaN(): Boolean
|
||||
expect fun Float.isNaN(): Boolean
|
||||
|
||||
public data class Pair<out A, out B>(public val first: A, public val second: B) : Serializable {
|
||||
public override fun toString(): String = "($first, $second)"
|
||||
}
|
||||
|
||||
public infix fun <A, B> A.to(that: B): Pair<A, B> = Pair(this, that)
|
||||
|
||||
public fun <T> Pair<T, T>.toList(): List<T> = listOf(first, second)
|
||||
|
||||
public data class Triple<out A, out B, out C>(
|
||||
public val first: A, public val second: B, public val third: C
|
||||
) : Serializable {
|
||||
public override fun toString(): String = "($first, $second, $third)"
|
||||
}
|
||||
|
||||
public fun <T> Triple<T, T, T>.toList(): List<T> = listOf(first, second, third)
|
||||
|
||||
public fun checkIndexOverflow(index: Int): Int {
|
||||
if (index < 0) {
|
||||
throw kotlin.ArithmeticException("Index overflow has happened.")
|
||||
}
|
||||
return index
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package kotlin.experimental
|
||||
|
||||
//Will return file and line number there this function was called
|
||||
inline fun sourceLocation(): String = throw kotlin.UnsupportedOperationException("Implemented as intrinsic")
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun numberIsInArray(array: IntArray, number: Int): Boolean {
|
||||
return number in array
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun valueIsInArray(array: Array<Any>, value: Any?): Boolean {
|
||||
return value in array
|
||||
}
|
||||
|
||||
const val a1 = <!EVALUATED: `true`!>numberIsInArray(intArrayOf(1, 2, 3), 1)<!>
|
||||
const val a2 = <!EVALUATED: `false`!>numberIsInArray(intArrayOf(1, 2, 3), -1)<!>
|
||||
|
||||
const val b1 = <!EVALUATED: `true`!>valueIsInArray(arrayOf(1, 2, 3), 1)<!>
|
||||
const val b2 = <!EVALUATED: `false`!>valueIsInArray(arrayOf(1, 2, 3), -1)<!>
|
||||
const val b3 = <!EVALUATED: `true`!>valueIsInArray(arrayOf(1, 2.0f, "3"), "3")<!>
|
||||
const val b4 = <!EVALUATED: `false`!>valueIsInArray(arrayOf(1, 2.0f, "3"), null)<!>
|
||||
const val b5 = <!EVALUATED: `false`!>valueIsInArray(arrayOf(1, 2.0f, "3"), 1.0f)<!>
|
||||
@@ -0,0 +1,39 @@
|
||||
@CompileTimeCalculation
|
||||
inline fun x(i: Int, w: () -> Int): Int {
|
||||
return i + w()
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun withNonLocalReturn(): String {
|
||||
x(10) { return "Non local" }
|
||||
return "Local"
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun withLocalReturn(): String {
|
||||
x(10) { return@x 1 }
|
||||
return "Local"
|
||||
}
|
||||
|
||||
// TODO can replace IrCall on IrConst inside body
|
||||
fun foo() {
|
||||
val a = x(10) l@ { //this call can be replaced on 20
|
||||
x(9) {
|
||||
return@l 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO can replace IrCall on IrConst inside body
|
||||
fun bar(p: Int) {
|
||||
x(10) {
|
||||
val i = p
|
||||
x(11) { //this call can be replaced on 21
|
||||
val j = 0
|
||||
x(j) { 10 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const val a = <!EVALUATED: `Non local`!>withNonLocalReturn()<!>
|
||||
const val b = <!EVALUATED: `Local`!>withLocalReturn()<!>
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
@CompileTimeCalculation
|
||||
class Outer {
|
||||
private val bar: String = "bar"
|
||||
val num = 1
|
||||
|
||||
fun foo() = "outer foo"
|
||||
|
||||
inner class Middle {
|
||||
val num = 2
|
||||
|
||||
fun foo() = "middle foo"
|
||||
|
||||
inner class Inner {
|
||||
val num = 3
|
||||
|
||||
fun foo() = "inner foo with outer bar = \"$bar\""
|
||||
|
||||
fun getAllNums() = "From inner: " + this.num + "; from middle: " + this@Middle.num + "; from outer: " + this@Outer.num
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const val a1 = Outer().<!EVALUATED: `outer foo`!>foo()<!>
|
||||
const val a2 = Outer().Middle().<!EVALUATED: `middle foo`!>foo()<!>
|
||||
const val a3 = Outer().Middle().Inner().<!EVALUATED: `inner foo with outer bar = "bar"`!>foo()<!>
|
||||
|
||||
const val b = Outer().Middle().Inner().<!EVALUATED: `From inner: 3; from middle: 2; from outer: 1`!>getAllNums()<!>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
interface Base
|
||||
|
||||
@CompileTimeCalculation
|
||||
open class A : Base
|
||||
|
||||
@CompileTimeCalculation
|
||||
class B : A()
|
||||
|
||||
const val a1 = 1 is Int
|
||||
const val a2 = 2 !is Int
|
||||
|
||||
const val b1 = <!EVALUATED: `true`!>A() is Base<!>
|
||||
const val b2 = <!EVALUATED: `false`!>A() !is Base<!>
|
||||
const val b3 = <!EVALUATED: `true`!>A() is A<!>
|
||||
const val b4 = <!EVALUATED: `false`!>A() !is A<!>
|
||||
|
||||
const val c1 = <!EVALUATED: `true`!>B() is Base<!>
|
||||
const val c2 = <!EVALUATED: `false`!>B() !is Base<!>
|
||||
const val c3 = <!EVALUATED: `true`!>B() is A<!>
|
||||
const val c4 = <!EVALUATED: `false`!>B() !is A<!>
|
||||
const val c5 = <!EVALUATED: `true`!>B() is B<!>
|
||||
const val c6 = <!EVALUATED: `false`!>B() !is B<!>
|
||||
@@ -0,0 +1,138 @@
|
||||
import kotlin.collections.*
|
||||
import kotlin.text.isEmpty
|
||||
|
||||
const val result1 = <!EVALUATED: `OK`!>foo()<!>
|
||||
const val result2 = <!EVALUATED: `OK`!>bar()<!>
|
||||
|
||||
const val result3 = <!EVALUATED: `fail 2; fail 3; fail 4; fail 5; fail 6; `!>checkForArrayList(1)<!>
|
||||
const val result4 = <!EVALUATED: `fail 5; fail 6; `!>checkForArrayList(listOf<Int>())<!>
|
||||
const val result5 = <!EVALUATED: `OK`!>checkForArrayList(arrayListOf<Int>())<!>
|
||||
|
||||
const val result6 = <!EVALUATED: `fail 1; fail 2; fail 3; fail 4; `!>checkForArray(1)<!>
|
||||
const val result7 = <!EVALUATED: `fail 1; fail 2; fail 3; fail 4; `!>checkForArray(intArrayOf())<!>
|
||||
const val result8 = <!EVALUATED: `fail 3; fail 4; `!>checkForArray(arrayOf<Int>())<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun foo(): String {
|
||||
val a = arrayListOf<Int>()
|
||||
if (a !is Collection<Int>) return "fail a 1"
|
||||
if (a !is Collection<Number>) return "fail a 2"
|
||||
if (a !is Collection<*>) return "fail a 3"
|
||||
|
||||
val b: ArrayList<Int>? = null
|
||||
if (b is Collection<Int>) return "fail b 1"
|
||||
if (b is Collection<Number>) return "fail b 2"
|
||||
if (b is Collection<*>) return "fail b 3"
|
||||
if (b is Collection<Any>) return "fail b 4"
|
||||
|
||||
if (b !is Collection<Int>?) return "fail b 5"
|
||||
if (b !is Collection<Number>?) return "fail b 6"
|
||||
if (b !is Collection<*>?) return "fail b 7"
|
||||
if (b !is Collection<Any>?) return "fail b 8"
|
||||
|
||||
if (b is Collection<Int?>) return "fail b 9"
|
||||
if (b is Collection<Number?>) return "fail b 10"
|
||||
if (b is Collection<Any?>) return "fail b 11"
|
||||
|
||||
if (b !is Collection<Int?>?) return "fail b 12"
|
||||
if (b !is Collection<Number?>?) return "fail b 13"
|
||||
if (b !is Collection<Any?>?) return "fail b 14"
|
||||
|
||||
val c: ArrayList<*> = arrayListOf(1, 2)
|
||||
if (c !is Collection<*>) return "fail c 1"
|
||||
if (c !is Collection<*>?) return "fail c 2"
|
||||
if (c !is Collection<Any?>?) return "fail c 3"
|
||||
|
||||
val d: ArrayList<Any> = arrayListOf(1, 2)
|
||||
if (d !is Collection<*>) return "fail d 1"
|
||||
if (d !is Collection<Any>) return "fail d 2"
|
||||
if (d !is Collection<*>?) return "fail d 3"
|
||||
if (d !is Collection<Any?>?) return "fail d 4"
|
||||
|
||||
val e: ArrayList<Any?> = arrayListOf(1, 2)
|
||||
if (e !is Collection<*>) return "fail e 1"
|
||||
if (e !is Collection<*>?) return "fail e 2"
|
||||
if (e !is Collection<Any?>?) return "fail e 3"
|
||||
|
||||
if (null is Any) return "fail f 1"
|
||||
if (null !is Any?) return "fail f 2"
|
||||
if (null is String) return "fail f 3"
|
||||
if (null !is String?) return "fail f 4"
|
||||
if (null is Nothing) return "fail f 5"
|
||||
if (null !is Nothing?) return "fail f 6"
|
||||
|
||||
val g: Int? = 1
|
||||
if (g !is Int) return "fail g 1"
|
||||
if (g !is Int?) return "fail g 2"
|
||||
|
||||
val h: Int = 1
|
||||
if (h !is Int) return "fail h 1"
|
||||
if (h !is Int?) return "fail h 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun bar(): String {
|
||||
val a = arrayListOf<Int>()
|
||||
if (a !is Collection<Int>) return "fail a 1"
|
||||
if (a !is Collection<Number>) return "fail a 2"
|
||||
if (a !is Collection<*>) return "fail a 3"
|
||||
|
||||
val b: Collection<Int>? = null
|
||||
if (b is ArrayList<Int>) return "fail b 1"
|
||||
if (b is ArrayList<*>) return "fail b 2"
|
||||
if (b !is ArrayList<Int>?) return "fail b 3"
|
||||
if (b !is ArrayList<*>?) return "fail b 4"
|
||||
|
||||
val c: Collection<*> = arrayListOf(1, 2)
|
||||
if (c !is ArrayList<*>) return "fail c 1"
|
||||
if (c !is ArrayList<*>?) return "fail c 2"
|
||||
|
||||
val d: Collection<Any> = arrayListOf(1, 2)
|
||||
if (d !is ArrayList<*>) return "fail d 1"
|
||||
if (d !is ArrayList<Any>) return "fail d 2"
|
||||
if (d !is ArrayList<*>?) return "fail d 3"
|
||||
|
||||
val e: Collection<Any?> = arrayListOf(1, 2)
|
||||
if (e !is Collection<*>) return "fail e 1"
|
||||
if (e !is Collection<*>?) return "fail e 2"
|
||||
if (e !is Collection<Any?>?) return "fail e 3"
|
||||
|
||||
val f: Any? = 1
|
||||
if (f !is Int) return "fail f 1"
|
||||
if (f !is Int?) return "fail f 2"
|
||||
|
||||
val g: Any = 1
|
||||
if (g !is Int) return "fail g 1"
|
||||
if (g !is Int?) return "fail g 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> checkForArrayList(value: T): String {
|
||||
val sb = StringBuilder()
|
||||
if (value !is Any) sb.append("fail 1; ")
|
||||
|
||||
if (value !is Collection<*>) sb.append("fail 2; ")
|
||||
if (value !is Collection<Any?>) sb.append("fail 3; ")
|
||||
if (value !is Collection<Any?>?) sb.append("fail 4; ")
|
||||
|
||||
if (value !is ArrayList<*>) sb.append("fail 5; ")
|
||||
if (value !is ArrayList<*>?) sb.append("fail 6; ")
|
||||
|
||||
return if (sb.isEmpty()) "OK" else sb.toString()
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T> checkForArray(value: T): String {
|
||||
val sb = StringBuilder()
|
||||
if (value !is Array<*>) sb.append("fail 1; ")
|
||||
if (value !is Array<*>?) sb.append("fail 2; ")
|
||||
|
||||
if (value !is ArrayList<*>) sb.append("fail 3; ")
|
||||
if (value !is ArrayList<*>?) sb.append("fail 4; ")
|
||||
|
||||
return if (sb.isEmpty()) "OK" else sb.toString()
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
interface A {
|
||||
@CompileTimeCalculation
|
||||
fun getStr(): String
|
||||
}
|
||||
|
||||
interface B : A {
|
||||
@CompileTimeCalculation
|
||||
fun getInt(): Int
|
||||
}
|
||||
|
||||
class C @CompileTimeCalculation constructor(@CompileTimeCalculation val num: Int) : B {
|
||||
@CompileTimeCalculation
|
||||
override fun getStr(): String {
|
||||
return num.toString()
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
override fun getInt(): Int {
|
||||
return num
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassAsA(num: Int): A {
|
||||
return C(num)
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassAsB(num: Int): B {
|
||||
return C(num)
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getClassAsC(num: Int): C {
|
||||
return C(num)
|
||||
}
|
||||
|
||||
const val num1 = getClassAsA(1).<!EVALUATED: `1`!>getStr()<!>
|
||||
const val num2 = getClassAsB(2).<!EVALUATED: `2`!>getStr()<!>
|
||||
const val num3 = getClassAsB(3).<!EVALUATED: `3`!>getInt()<!>
|
||||
const val num4 = getClassAsC(4).<!EVALUATED: `4`!>getStr()<!>
|
||||
const val num5 = getClassAsC(5).<!EVALUATED: `5`!>getInt()<!>
|
||||
@@ -0,0 +1,30 @@
|
||||
@CompileTimeCalculation
|
||||
interface A {
|
||||
fun getInt(): Int
|
||||
|
||||
fun getStr(): String = "Number is ${getInt()}"
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
class B(val b: Int) : A {
|
||||
override fun getInt(): Int = b
|
||||
|
||||
fun getStrFromB() = "B " + super.getStr()
|
||||
}
|
||||
|
||||
const val str1 = B(5).<!EVALUATED: `Number is 5`!>getStr()<!>
|
||||
const val str2 = B(5).<!EVALUATED: `B Number is 5`!>getStrFromB()<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
interface C {
|
||||
val num: Int
|
||||
fun getInt() = num
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
class D(override val num: Int) : C {
|
||||
fun getStr() = "D num = " + super.getInt()
|
||||
}
|
||||
|
||||
const val num1 = D(10).<!EVALUATED: `10`!>getInt()<!>
|
||||
const val num2 = D(10).<!EVALUATED: `D num = 10`!>getStr()<!>
|
||||
@@ -0,0 +1,49 @@
|
||||
package test
|
||||
|
||||
import kotlin.reflect.KFunction
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
class A(val a: Int, val b: String) {
|
||||
val String.propertyWithExtension: Int
|
||||
get() = this.length * a
|
||||
|
||||
fun Int.funWithExtension(other: Int) = this + other
|
||||
}
|
||||
|
||||
const val aSimpleName = <!EVALUATED: `A`!>A::class.simpleName!!<!>
|
||||
const val aQualifiedName = <!EVALUATED: `test.A`!>A::class.qualifiedName!!<!>
|
||||
//const val aMembers = A::class.members.joinToString() TODO -> `val test.A.a: kotlin.Int, val test.A.b: kotlin.String, val test.A.(kotlin.String.)propertyWithExtension: kotlin.Int, fun test.A.(kotlin.Int.)funWithExtension(kotlin.Int): kotlin.Int, fun test.A.equals(kotlin.Any?): kotlin.Boolean, fun test.A.hashCode(): kotlin.Int, fun test.A.toString(): kotlin.String`
|
||||
const val aConstructors = A::class.constructors.<!EVALUATED: `fun <init>(kotlin.Int, kotlin.String): test.A`!>joinToString()<!>
|
||||
const val aVisibility = A::class.visibility.<!EVALUATED: `PUBLIC`!>toString()<!>
|
||||
const val aSupertypes = A::class.supertypes.<!EVALUATED: `kotlin.Any`!>joinToString()<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
interface Base<T>
|
||||
|
||||
@CompileTimeCalculation
|
||||
class B<T, E : T, D : Any>(val prop: T) : Base<T> {
|
||||
fun get(): T = prop
|
||||
|
||||
fun getThis(): B<T, out E, in D> = this
|
||||
|
||||
fun <E : Number> withTypeParameter(num: E) = num.toString()
|
||||
}
|
||||
|
||||
//const val bMembers = B::class.members.joinToString() TODO -> `val test.B<T, E, D>.prop: T, fun test.B<T, E, D>.get(): T, fun test.B<T, E, D>.getThis(): test.B<T, out E, in D>, fun test.B<T, E, D>.withTypeParameter(E): kotlin.String, fun test.B<T, E, D>.equals(kotlin.Any?): kotlin.Boolean, fun test.B<T, E, D>.hashCode(): kotlin.Int, fun test.B<T, E, D>.toString(): kotlin.String`
|
||||
const val bTypeParameters = B::class.typeParameters.<!EVALUATED: `T, E, D`!>joinToString()<!>
|
||||
const val bSupertypes = B::class.supertypes.<!EVALUATED: `test.Base<T>, kotlin.Any`!>joinToString()<!>
|
||||
//const val bReturnType1 = B::class.members.toList()[1].returnType.toString() TODO -> `T`
|
||||
//const val bReturnType2 = B::class.members.toList()[3].returnType.toString() TODO -> `kotlin.String`
|
||||
|
||||
const val arguments1 = (B<Number, Double, Int>(1)::getThis as KFunction<*>).returnType.arguments.<!EVALUATED: `T, out E, in D`!>joinToString()<!>
|
||||
const val arguments2 = (arrayOf(1)::iterator as KFunction<*>).returnType.arguments.<!EVALUATED: `T`!>joinToString()<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
class C {
|
||||
val String.getLength
|
||||
get() = this.length
|
||||
}
|
||||
|
||||
//const val cMember = C::class.members.toList()[0].toString() TODO -> `val test.C.(kotlin.String.)getLength: kotlin.Int`
|
||||
//const val cMemberReturnType = C::class.members.toList()[0].returnType.classifier.toString() TODO -> `class kotlin.Int`
|
||||
@@ -0,0 +1,26 @@
|
||||
const val byteMax = <!EVALUATED: `127`!>{ java.lang.Byte.MAX_VALUE }()<!>
|
||||
const val byteMin = <!EVALUATED: `-128`!>{ java.lang.Byte.MIN_VALUE }()<!>
|
||||
const val byteSize = <!EVALUATED: `8`!>{ java.lang.Byte.SIZE }()<!>
|
||||
const val byteBytes = <!EVALUATED: `1`!>{ java.lang.Byte.BYTES }()<!>
|
||||
|
||||
const val intMax = <!EVALUATED: `2147483647`!>{ java.lang.Integer.MAX_VALUE }()<!>
|
||||
const val intMin = <!EVALUATED: `-2147483648`!>{ java.lang.Integer.MIN_VALUE }()<!>
|
||||
const val intSize = <!EVALUATED: `32`!>{ java.lang.Integer.SIZE }()<!>
|
||||
const val intBytes = <!EVALUATED: `4`!>{ java.lang.Integer.BYTES }()<!>
|
||||
|
||||
const val floatMax = <!EVALUATED: `3.4028235E38`!>{ java.lang.Float.MAX_VALUE }()<!>
|
||||
const val floatMin = <!EVALUATED: `1.4E-45`!>{ java.lang.Float.MIN_VALUE }()<!>
|
||||
const val floatSize = <!EVALUATED: `32`!>{ java.lang.Float.SIZE }()<!>
|
||||
const val floatBytes = <!EVALUATED: `4`!>{ java.lang.Float.BYTES }()<!>
|
||||
const val floatMaxExponent = <!EVALUATED: `127`!>{ java.lang.Float.MAX_EXPONENT }()<!>
|
||||
const val floatMinExponent = <!EVALUATED: `-126`!>{ java.lang.Float.MIN_EXPONENT }()<!>
|
||||
const val floatNegInfinity = <!EVALUATED: `-Infinity`!>{ java.lang.Float.NEGATIVE_INFINITY }()<!>
|
||||
const val floatPosInfinity = <!EVALUATED: `Infinity`!>{ java.lang.Float.POSITIVE_INFINITY }()<!>
|
||||
|
||||
const val booleanFalse = { java.lang.Boolean.FALSE }().<!EVALUATED: `false`!>toString()<!>
|
||||
const val booleanTrue = { java.lang.Boolean.TRUE }().<!EVALUATED: `true`!>toString()<!>
|
||||
|
||||
const val charMax = { java.lang.Character.MAX_VALUE }().<!EVALUATED: `65535`!>toInt()<!>
|
||||
const val charMin = { java.lang.Character.MIN_VALUE }().<!EVALUATED: `0`!>toInt()<!>
|
||||
const val charSize = <!EVALUATED: `16`!>{ java.lang.Character.SIZE }()<!>
|
||||
const val charBytes = <!EVALUATED: `2`!>{ java.lang.Character.BYTES }()<!>
|
||||
@@ -0,0 +1,11 @@
|
||||
package test
|
||||
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
class A(val a: Int) {
|
||||
val String.size: Int
|
||||
get() = this.length * a
|
||||
}
|
||||
|
||||
//const val kproperty2Get = A::class.members.toList()[1].call(A(2), "123").toString() TODO -> `6`
|
||||
@@ -0,0 +1,29 @@
|
||||
package test
|
||||
|
||||
import kotlin.reflect.KFunction
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun withParameters(a: Int, b: Double) = 0
|
||||
@CompileTimeCalculation
|
||||
fun String.withExtension(a: Int) = 0
|
||||
|
||||
@CompileTimeCalculation
|
||||
class A {
|
||||
fun String.get(a: Int) = this
|
||||
}
|
||||
|
||||
const val parameters1 = (::withParameters as KFunction<*>).parameters.<!EVALUATED: `parameter #0 a of fun withParameters(kotlin.Int, kotlin.Double): kotlin.Int, parameter #1 b of fun withParameters(kotlin.Int, kotlin.Double): kotlin.Int`!>joinToString()<!>
|
||||
const val parameters2 = (String::withExtension as KFunction<*>).parameters.<!EVALUATED: `extension receiver parameter of fun kotlin.String.withExtension(kotlin.Int): kotlin.Int, parameter #1 a of fun kotlin.String.withExtension(kotlin.Int): kotlin.Int`!>joinToString()<!>
|
||||
//const val parameters3 = A::class.members.toList()[0].parameters.joinToString() TODO -> `instance parameter of fun test.A.(kotlin.String.)get(kotlin.Int): kotlin.String, extension receiver parameter of fun test.A.(kotlin.String.)get(kotlin.Int): kotlin.String, parameter #2 a of fun test.A.(kotlin.String.)get(kotlin.Int): kotlin.String`
|
||||
|
||||
// properties
|
||||
@CompileTimeCalculation
|
||||
class B(val b: Int) {
|
||||
val String.size: Int
|
||||
get() = this.length
|
||||
}
|
||||
|
||||
const val property0Parameters = B(1)::b.parameters.<!EVALUATED: `[]`!>toString()<!>
|
||||
const val property1Parameters = B::b.parameters.<!EVALUATED: `[instance parameter of val test.B.b: kotlin.Int]`!>toString()<!>
|
||||
//const val property2Parameters = B::class.members.toList()[1].parameters.toString() TODO -> `[instance parameter of val test.B.(kotlin.String.)size: kotlin.Int, extension receiver parameter of val test.B.(kotlin.String.)size: kotlin.Int]`
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
@CompileTimeCalculation
|
||||
fun withLambda(arg: Int, function: (Int) -> Int): Int {
|
||||
return function(arg)
|
||||
}
|
||||
|
||||
const val a1 = <!EVALUATED: `20`!>withLambda(10) { it * 2 }<!>
|
||||
const val a2 = <!EVALUATED: `40`!>withLambda(20, { num -> num * 2 })<!>
|
||||
const val a3 = <!EVALUATED: `60`!>withLambda(30, @CompileTimeCalculation fun(number: Int) = number * 2)<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T, E, R> withLambda2(arg1: T, arg2: E, function: (T, E) -> R): R {
|
||||
return function.invoke(arg1, arg2)
|
||||
}
|
||||
|
||||
const val b1 = <!EVALUATED: `13.75`!>withLambda2(5, 2.75) { arg1, arg2 -> arg1 * arg2 }<!>
|
||||
const val b2 = <!EVALUATED: `25`!>withLambda2(5, "unused") { arg1, _ -> arg1 * 5 }<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun <T, E, R> withLambdaAndReceiver(arg1: T, arg2: E, function: T.(E) -> R): R {
|
||||
return function.invoke(arg1, arg2) // arg1.function(arg2)
|
||||
}
|
||||
|
||||
const val c1 = <!EVALUATED: `7.75`!>withLambdaAndReceiver(5, 2.75) { arg -> this.plus(arg) }<!>
|
||||
@@ -0,0 +1,55 @@
|
||||
@CompileTimeCalculation
|
||||
fun returnTheSameValueFun(num: Int) = fun(): Int { return num }
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun multiplyByTwo(num: Int): () -> Int {
|
||||
val a = 2
|
||||
val b = 5
|
||||
return fun(): Int { return num * a }
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
inline fun multiplyBy(noinline multiply: (Int, Int) -> Int): (Int, Int) -> Int {
|
||||
return multiply
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun checkStackCorrectness(): Int {
|
||||
returnTheSameValueFun(10).invoke()
|
||||
val num = 5
|
||||
return num
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun checkLaterInvoke(): String {
|
||||
val num = 10
|
||||
val function = multiplyByTwo(num)
|
||||
val b = 0
|
||||
return "previous = " + num + "; multiplied by two = " + function.invoke() + "; b = " + b
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun localInline(): String {
|
||||
val a = 10
|
||||
val b = 20
|
||||
val function = multiplyBy() { a, b -> (a + b) * 2 }.invoke(1, 3)
|
||||
return "result = " + function + "; (a, b) = ($a, $b)"
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getNumAfterLocalInvoke(): Int {
|
||||
var a = 1
|
||||
@CompileTimeCalculation
|
||||
fun local() {
|
||||
a++
|
||||
}
|
||||
local()
|
||||
return a
|
||||
}
|
||||
|
||||
const val a = returnTheSameValueFun(2).<!EVALUATED: `2`!>invoke()<!>
|
||||
const val b = multiplyByTwo(1).<!EVALUATED: `2`!>invoke()<!>
|
||||
const val c = <!EVALUATED: `5`!>checkStackCorrectness()<!>
|
||||
const val d = <!EVALUATED: `previous = 10; multiplied by two = 20; b = 0`!>checkLaterInvoke()<!>
|
||||
const val e = <!EVALUATED: `result = 8; (a, b) = (10, 20)`!>localInline()<!>
|
||||
const val f = <!EVALUATED: `2`!>getNumAfterLocalInvoke()<!>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
@CompileTimeCalculation
|
||||
interface LocalObject {
|
||||
fun getNum(): Int
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getLocalObject(num: Int) = object : LocalObject {
|
||||
override fun getNum() = num
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
class A(val a: Int) {
|
||||
val localObject = object : LocalObject {
|
||||
override fun getNum() = a
|
||||
}
|
||||
}
|
||||
|
||||
const val a = getLocalObject(10).<!EVALUATED: `10`!>getNum()<!>
|
||||
const val b = A(2).localObject.<!EVALUATED: `2`!>getNum()<!>
|
||||
@@ -0,0 +1,35 @@
|
||||
// FILE: logIntrinsic.kt
|
||||
|
||||
import kotlin.experimental.*
|
||||
|
||||
const val thisFileInfo = <!EVALUATED: `logIntrinsic.kt:5`!>sourceLocation()<!>
|
||||
const val otherFileInfo = <!EVALUATED: `other.kt:29`!>getSomeInfo()<!>
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun sumWithLog(a: Int, b: Int): String {
|
||||
val firstWord = <!EVALUATED: `logIntrinsic.kt:10`!>log("Function start")<!>
|
||||
val before = <!EVALUATED: `logIntrinsic.kt:11`!>log("Start summation of $a and $b")<!>
|
||||
val after = <!EVALUATED: `logIntrinsic.kt:12`!>log("Result of summation is ${a + b}")<!>
|
||||
val finalWord = log("Function end", "<WITHOUT FILE>")
|
||||
|
||||
return "\n" + firstWord + "\n" + before + "\n" + after + "\n" + finalWord
|
||||
}
|
||||
|
||||
const val sum = <!EVALUATED: `
|
||||
Function start at logIntrinsic.kt:10
|
||||
Start summation of 2 and 5 at logIntrinsic.kt:11
|
||||
Result of summation is 7 at logIntrinsic.kt:12
|
||||
Function end at <WITHOUT FILE>`!>sumWithLog(2, 5)<!>
|
||||
|
||||
// FILE: other.kt
|
||||
import kotlin.experimental.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun getSomeInfo(): String {
|
||||
return sourceLocation()
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
inline fun log(info: String, fileNameAndLine: String = sourceLocation()): String {
|
||||
return info + " at " + fileNameAndLine
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
@CompileTimeCalculation
|
||||
fun loop(toInc: Int, start: Int, end: Int): Int {
|
||||
var result = toInc
|
||||
for (i in start..end) {
|
||||
result += 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun withInnerContinue(): Int {
|
||||
var cycles = 0
|
||||
var i = 1
|
||||
var j = 1
|
||||
L@while (i <= 5) {
|
||||
j = 1
|
||||
while (j <= 5) {
|
||||
if (i % 2 == 0) {
|
||||
i += 1
|
||||
continue@L
|
||||
}
|
||||
cycles += 1
|
||||
j += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
return cycles
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun withBreak(limit: Int): Int {
|
||||
var x = 0
|
||||
while(true) {
|
||||
if(x < limit) x++ else break
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun earlyExit(end: Int, stop: Int): Int {
|
||||
for (i in 1..end) {
|
||||
if (i == stop) return i
|
||||
}
|
||||
return end
|
||||
}
|
||||
|
||||
const val a = <!EVALUATED: `10`!>loop(0, 1, 10)<!>
|
||||
const val b1 = <!EVALUATED: `15`!>withInnerContinue()<!>
|
||||
const val b2 = <!EVALUATED: `10`!>withBreak(10)<!>
|
||||
const val c1 = <!EVALUATED: `5`!>earlyExit(10, 5)<!>
|
||||
const val c2 = <!EVALUATED: `10`!>earlyExit(10, 15)<!>
|
||||
@@ -0,0 +1,23 @@
|
||||
@CompileTimeCalculation
|
||||
open class A {
|
||||
open fun get(): Int { return 1 }
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
interface B {
|
||||
fun get(): Int = 2
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
interface C {
|
||||
fun get(): Int = 3
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
class D : A(), B, C {
|
||||
override fun get(): Int {
|
||||
return super<C>.get() + super<B>.get() + super<A>.get()
|
||||
}
|
||||
}
|
||||
|
||||
const val a = D().<!EVALUATED: `6`!>get()<!>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
class A {
|
||||
const val a = <!EVALUATED: `10`!>{ 10 }()<!>
|
||||
|
||||
companion object {
|
||||
const val static = <!EVALUATED: `-10`!>{ -10 }()<!>
|
||||
|
||||
fun getStaticNumber(): Int {
|
||||
return Int.MAX_VALUE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object ObjectWithConst {
|
||||
const val a = 100
|
||||
const val b = <!EVALUATED: `Value in a: 100`!>concat("Value in a: ", a)<!>
|
||||
|
||||
fun concat(first: String, second: Any) = "$first$second"
|
||||
}
|
||||
|
||||
const val num = A().<!EVALUATED: `10`!>a<!>
|
||||
const val numStatic = A.<!EVALUATED: `-10`!>static<!>
|
||||
const val numStaticFromFun = A.<!EVALUATED: `2147483647`!>getStaticNumber()<!>
|
||||
const val valFromObject = ObjectWithConst.<!EVALUATED: `Value in a: 100`!>b<!>
|
||||
@@ -0,0 +1,27 @@
|
||||
@CompileTimeCalculation
|
||||
interface Object {
|
||||
fun get(): String
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun defaultGet() = "Object"
|
||||
}
|
||||
|
||||
object A : Object {
|
||||
@CompileTimeCalculation
|
||||
override fun get() = "A"
|
||||
}
|
||||
|
||||
open class B : Object {
|
||||
@CompileTimeCalculation
|
||||
override fun get() = "B"
|
||||
}
|
||||
|
||||
object C : B() {
|
||||
@CompileTimeCalculation
|
||||
override fun get() = "Default: " + super.defaultGet() + "; from super B: " + super.get() + "; from current: " + "companion C"
|
||||
}
|
||||
|
||||
const val a1 = A.<!EVALUATED: `Object`!>defaultGet()<!>
|
||||
const val a2 = A.<!EVALUATED: `A`!>get()<!>
|
||||
const val c1 = C.<!EVALUATED: `Object`!>defaultGet()<!>
|
||||
const val c2 = C.<!EVALUATED: `Default: Object; from super B: B; from current: companion C`!>get()<!>
|
||||
@@ -0,0 +1,14 @@
|
||||
@CompileTimeCalculation
|
||||
open class A {
|
||||
open fun inc(i: Int) = i + 1
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
class B(val b: Int) : A() {
|
||||
override fun inc(j: Int): Int {
|
||||
return j + b
|
||||
}
|
||||
}
|
||||
|
||||
const val a = A().<!EVALUATED: `11`!>inc(10)<!>
|
||||
const val b = B(10).<!EVALUATED: `21`!>inc(11)<!>
|
||||
@@ -0,0 +1,14 @@
|
||||
@CompileTimeCalculation
|
||||
open class A {
|
||||
open fun String.getSize() = this.length
|
||||
|
||||
fun returnSizeOf(str: String) = str.getSize()
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
class B : A() {
|
||||
override fun String.getSize() = -1
|
||||
}
|
||||
|
||||
const val a = A().<!EVALUATED: `4`!>returnSizeOf("1234")<!>
|
||||
const val b = B().<!EVALUATED: `-1`!>returnSizeOf("1234")<!>
|
||||
@@ -0,0 +1,43 @@
|
||||
fun compareTo(first: Char, second: Char) = first.compareTo(second)
|
||||
|
||||
fun plus(first: Char, second: Int) = first.plus(second)
|
||||
|
||||
fun minus(first: Char, second: Char) = first.minus(second)
|
||||
fun minus(first: Char, second: Int) = first.minus(second)
|
||||
|
||||
fun inc(first: Char) = first.inc()
|
||||
fun dec(first: Char) = first.dec()
|
||||
|
||||
fun rangeTo(first: Char, second: Char) = first.rangeTo(second)
|
||||
|
||||
fun toByte(first: Char) = first.toByte()
|
||||
fun toChar(first: Char) = first.toChar()
|
||||
fun toShort(first: Char) = first.toShort()
|
||||
fun toInt(first: Char) = first.toInt()
|
||||
fun toLong(first: Char) = first.toLong()
|
||||
fun toFloat(first: Char) = first.toFloat()
|
||||
fun toDouble(first: Char) = first.toDouble()
|
||||
|
||||
fun toString(first: Char) = first.toString()
|
||||
fun hashCode(first: Char) = first.hashCode()
|
||||
fun equals(first: Char, second: Char) = first.equals(second)
|
||||
|
||||
const val a1 = <!EVALUATED: `-1`!>compareTo('a', 'b')<!>
|
||||
const val a2 = <!EVALUATED: `3`!>plus('1', 2)<!>
|
||||
const val a3 = <!EVALUATED: `8`!>minus('9', '1')<!>
|
||||
const val a4 = <!EVALUATED: `8`!>minus('9', 1)<!>
|
||||
const val a5 = <!EVALUATED: `2`!>inc('1')<!>
|
||||
const val a6 = <!EVALUATED: `0`!>dec('1')<!>
|
||||
const val a7 = rangeTo('9', '1').<!EVALUATED: `1`!>last<!>
|
||||
|
||||
const val b1 = <!EVALUATED: `49`!>toByte('1')<!>
|
||||
const val b2 = <!EVALUATED: `2`!>toChar('2')<!>
|
||||
const val b3 = <!EVALUATED: `51`!>toShort('3')<!>
|
||||
const val b4 = <!EVALUATED: `52`!>toInt('4')<!>
|
||||
const val b5 = <!EVALUATED: `53`!>toLong('5')<!>
|
||||
const val b6 = <!EVALUATED: `54.0`!>toFloat('6')<!>
|
||||
const val b7 = <!EVALUATED: `55.0`!>toDouble('7')<!>
|
||||
|
||||
const val c1 = <!EVALUATED: `q`!>toString('q')<!>
|
||||
const val c2 = <!EVALUATED: `113`!>hashCode('q')<!>
|
||||
const val c3 = <!EVALUATED: `false`!>equals('1', '2')<!>
|
||||
@@ -0,0 +1,156 @@
|
||||
@CompileTimeCalculation fun compareTo(value: Int, other: Byte) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: Int, other: Short) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: Int, other: Int) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: Int, other: Long) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: Int, other: Float) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: Int, other: Double) = value.compareTo(other)
|
||||
|
||||
@CompileTimeCalculation fun plus(value: Int, other: Byte) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: Int, other: Short) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: Int, other: Int) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: Int, other: Long) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: Int, other: Float) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: Int, other: Double) = value.plus(other)
|
||||
|
||||
@CompileTimeCalculation fun minus(value: Int, other: Byte) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: Int, other: Short) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: Int, other: Int) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: Int, other: Long) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: Int, other: Float) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: Int, other: Double) = value.minus(other)
|
||||
|
||||
@CompileTimeCalculation fun times(value: Int, other: Byte) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: Int, other: Short) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: Int, other: Int) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: Int, other: Long) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: Int, other: Float) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: Int, other: Double) = value.times(other)
|
||||
|
||||
@CompileTimeCalculation fun div(value: Int, other: Byte) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: Int, other: Short) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: Int, other: Int) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: Int, other: Long) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: Int, other: Float) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: Int, other: Double) = value.div(other)
|
||||
|
||||
@CompileTimeCalculation fun rem(value: Int, other: Byte) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: Int, other: Short) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: Int, other: Int) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: Int, other: Long) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: Int, other: Float) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: Int, other: Double) = value.rem(other)
|
||||
|
||||
@CompileTimeCalculation fun inc(value: Int) = value.inc()
|
||||
@CompileTimeCalculation fun dec(value: Int) = value.dec()
|
||||
|
||||
@CompileTimeCalculation fun unaryPlus(value: Int) = value.unaryPlus()
|
||||
@CompileTimeCalculation fun unaryMinus(value: Int) = value.unaryMinus()
|
||||
|
||||
@CompileTimeCalculation fun rangeTo(value: Int, other: Byte) = value.rangeTo(other)
|
||||
@CompileTimeCalculation fun rangeTo(value: Int, other: Short) = value.rangeTo(other)
|
||||
@CompileTimeCalculation fun rangeTo(value: Int, other: Int) = value.rangeTo(other)
|
||||
@CompileTimeCalculation fun rangeTo(value: Int, other: Long) = value.rangeTo(other)
|
||||
|
||||
@CompileTimeCalculation fun shl(value: Int, bitCount: Int) = value.shl(bitCount)
|
||||
@CompileTimeCalculation fun shr(value: Int, bitCount: Int) = value.shr(bitCount)
|
||||
@CompileTimeCalculation fun ushr(value: Int, bitCount: Int) = value.ushr(bitCount)
|
||||
|
||||
@CompileTimeCalculation fun and(value: Int, other: Int) = value.and(other)
|
||||
@CompileTimeCalculation fun or(value: Int, other: Int) = value.or(other)
|
||||
@CompileTimeCalculation fun xor(value: Int, other: Int) = value.xor(other)
|
||||
@CompileTimeCalculation fun inv(value: Int) = value.inv()
|
||||
|
||||
@CompileTimeCalculation fun toByte(value: Int) = value.toByte()
|
||||
@CompileTimeCalculation fun toChar(value: Int) = value.toChar()
|
||||
@CompileTimeCalculation fun toShort(value: Int) = value.toShort()
|
||||
@CompileTimeCalculation fun toInt(value: Int) = value.toInt()
|
||||
@CompileTimeCalculation fun toLong(value: Int) = value.toLong()
|
||||
@CompileTimeCalculation fun toFloat(value: Int) = value.toFloat()
|
||||
@CompileTimeCalculation fun toDouble(value: Int) = value.toDouble()
|
||||
|
||||
@CompileTimeCalculation fun toString(value: Int) = value.toString()
|
||||
@CompileTimeCalculation fun hashCode(value: Int) = value.hashCode()
|
||||
@CompileTimeCalculation fun equals(value: Int, other: Int) = value.equals(other)
|
||||
|
||||
@CompileTimeCalculation fun echo(value: Int) = value
|
||||
|
||||
const val min = <!EVALUATED: `-2147483648`!>echo(Int.MIN_VALUE)<!>
|
||||
const val max = <!EVALUATED: `2147483647`!>echo(Int.MAX_VALUE)<!>
|
||||
const val bytes = <!EVALUATED: `4`!>echo(Int.SIZE_BYTES)<!>
|
||||
const val bits = <!EVALUATED: `32`!>echo(Int.SIZE_BITS)<!>
|
||||
|
||||
const val compare1 = <!EVALUATED: `1`!>compareTo(5, 1.toByte())<!>
|
||||
const val compare2 = <!EVALUATED: `1`!>compareTo(5, 2.toShort())<!>
|
||||
const val compare3 = <!EVALUATED: `1`!>compareTo(5, 3)<!>
|
||||
const val compare4 = <!EVALUATED: `1`!>compareTo(5, 4L)<!>
|
||||
const val compare5 = <!EVALUATED: `0`!>compareTo(5, 5.toFloat())<!>
|
||||
const val compare6 = <!EVALUATED: `-1`!>compareTo(5, 6.toDouble())<!>
|
||||
|
||||
const val plus1 = <!EVALUATED: `6`!>plus(5, 1.toByte())<!>
|
||||
const val plus2 = <!EVALUATED: `7`!>plus(5, 2.toShort())<!>
|
||||
const val plus3 = <!EVALUATED: `8`!>plus(5, 3)<!>
|
||||
const val plus4 = <!EVALUATED: `9`!>plus(5, 4L)<!>
|
||||
const val plus5 = <!EVALUATED: `10.0`!>plus(5, 5.toFloat())<!>
|
||||
const val plus6 = <!EVALUATED: `11.0`!>plus(5, 6.toDouble())<!>
|
||||
|
||||
const val minus1 = <!EVALUATED: `4`!>minus(5, 1.toByte())<!>
|
||||
const val minus2 = <!EVALUATED: `3`!>minus(5, 2.toShort())<!>
|
||||
const val minus3 = <!EVALUATED: `2`!>minus(5, 3)<!>
|
||||
const val minus4 = <!EVALUATED: `1`!>minus(5, 4L)<!>
|
||||
const val minus5 = <!EVALUATED: `0.0`!>minus(5, 5.toFloat())<!>
|
||||
const val minus6 = <!EVALUATED: `-1.0`!>minus(5, 6.toDouble())<!>
|
||||
|
||||
const val times1 = <!EVALUATED: `5`!>times(5, 1.toByte())<!>
|
||||
const val times2 = <!EVALUATED: `10`!>times(5, 2.toShort())<!>
|
||||
const val times3 = <!EVALUATED: `15`!>times(5, 3)<!>
|
||||
const val times4 = <!EVALUATED: `20`!>times(5, 4L)<!>
|
||||
const val times5 = <!EVALUATED: `25.0`!>times(5, 5.toFloat())<!>
|
||||
const val times6 = <!EVALUATED: `30.0`!>times(5, 6.toDouble())<!>
|
||||
|
||||
const val div1 = <!EVALUATED: `100`!>div(100, 1.toByte())<!>
|
||||
const val div2 = <!EVALUATED: `50`!>div(100, 2.toShort())<!>
|
||||
const val div3 = <!EVALUATED: `25`!>div(100, 4)<!>
|
||||
const val div4 = <!EVALUATED: `10`!>div(100, 10L)<!>
|
||||
const val div5 = <!EVALUATED: `4.0`!>div(100, 25.toFloat())<!>
|
||||
const val div6 = <!EVALUATED: `2.0`!>div(100, 50.toDouble())<!>
|
||||
|
||||
const val rem1 = <!EVALUATED: `0`!>rem(5, 1.toByte())<!>
|
||||
const val rem2 = <!EVALUATED: `1`!>rem(5, 2.toShort())<!>
|
||||
const val rem3 = <!EVALUATED: `2`!>rem(5, 3)<!>
|
||||
const val rem4 = <!EVALUATED: `1`!>rem(5, 4L)<!>
|
||||
const val rem5 = <!EVALUATED: `0.0`!>rem(5, 5.toFloat())<!>
|
||||
const val rem6 = <!EVALUATED: `5.0`!>rem(5, 6.toDouble())<!>
|
||||
|
||||
const val increment = <!EVALUATED: `4`!>inc(3)<!>
|
||||
const val decrement = <!EVALUATED: `2`!>dec(3)<!>
|
||||
|
||||
const val unaryPlus = <!EVALUATED: `3`!>unaryPlus(3)<!>
|
||||
const val unaryMinus = <!EVALUATED: `-3`!>unaryMinus(3)<!>
|
||||
|
||||
const val rangeTo1 = rangeTo(5, 1.toByte()).<!EVALUATED: `1`!>last<!>
|
||||
const val rangeTo2 = rangeTo(5, 2.toShort()).<!EVALUATED: `2`!>last<!>
|
||||
const val rangeTo3 = rangeTo(5, 3).<!EVALUATED: `3`!>last<!>
|
||||
const val rangeTo4 = rangeTo(5, 4L).<!EVALUATED: `4`!>last<!>
|
||||
|
||||
const val shiftLeft = <!EVALUATED: `16`!>shl(8, 1)<!>
|
||||
const val shiftRight = <!EVALUATED: `2`!>shr(8, 2)<!>
|
||||
const val unsignedShiftRight = <!EVALUATED: `536870911`!>ushr(-8, 3)<!>
|
||||
|
||||
const val and = <!EVALUATED: `0`!>and(8, 1)<!>
|
||||
const val or = <!EVALUATED: `10`!>or(8, 2)<!>
|
||||
const val xor = <!EVALUATED: `-5`!>xor(-8, 3)<!>
|
||||
const val inv = <!EVALUATED: `-9`!>inv(8)<!>
|
||||
|
||||
const val a1 = <!EVALUATED: `1`!>toByte(1)<!>
|
||||
const val a2 = <!EVALUATED: ``!>toChar(2)<!>
|
||||
const val a3 = <!EVALUATED: `3`!>toShort(3)<!>
|
||||
const val a4 = <!EVALUATED: `4`!>toInt(4)<!>
|
||||
const val a5 = <!EVALUATED: `5`!>toLong(5)<!>
|
||||
const val a6 = <!EVALUATED: `6.0`!>toFloat(6)<!>
|
||||
const val a7 = <!EVALUATED: `7.0`!>toDouble(7)<!>
|
||||
|
||||
const val b1 = <!EVALUATED: `10`!>toString(10)<!>
|
||||
const val b2 = <!EVALUATED: `10`!>hashCode(10)<!>
|
||||
const val b3 = <!EVALUATED: `false`!>equals(10, 11)<!>
|
||||
const val b4 = <!EVALUATED: `true`!>equals(1, 1.toInt())<!>
|
||||
const val b5 = <!EVALUATED: `true`!>equals(1, 1)<!>
|
||||
@@ -0,0 +1,156 @@
|
||||
@CompileTimeCalculation fun compareTo(value: Long, other: Byte) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: Long, other: Short) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: Long, other: Int) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: Long, other: Long) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: Long, other: Float) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: Long, other: Double) = value.compareTo(other)
|
||||
|
||||
@CompileTimeCalculation fun plus(value: Long, other: Byte) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: Long, other: Short) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: Long, other: Int) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: Long, other: Long) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: Long, other: Float) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: Long, other: Double) = value.plus(other)
|
||||
|
||||
@CompileTimeCalculation fun minus(value: Long, other: Byte) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: Long, other: Short) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: Long, other: Int) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: Long, other: Long) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: Long, other: Float) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: Long, other: Double) = value.minus(other)
|
||||
|
||||
@CompileTimeCalculation fun times(value: Long, other: Byte) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: Long, other: Short) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: Long, other: Int) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: Long, other: Long) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: Long, other: Float) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: Long, other: Double) = value.times(other)
|
||||
|
||||
@CompileTimeCalculation fun div(value: Long, other: Byte) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: Long, other: Short) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: Long, other: Int) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: Long, other: Long) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: Long, other: Float) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: Long, other: Double) = value.div(other)
|
||||
|
||||
@CompileTimeCalculation fun rem(value: Long, other: Byte) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: Long, other: Short) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: Long, other: Int) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: Long, other: Long) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: Long, other: Float) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: Long, other: Double) = value.rem(other)
|
||||
|
||||
@CompileTimeCalculation fun inc(value: Long) = value.inc()
|
||||
@CompileTimeCalculation fun dec(value: Long) = value.dec()
|
||||
|
||||
@CompileTimeCalculation fun unaryPlus(value: Long) = value.unaryPlus()
|
||||
@CompileTimeCalculation fun unaryMinus(value: Long) = value.unaryMinus()
|
||||
|
||||
@CompileTimeCalculation fun rangeTo(value: Long, other: Byte) = value.rangeTo(other)
|
||||
@CompileTimeCalculation fun rangeTo(value: Long, other: Short) = value.rangeTo(other)
|
||||
@CompileTimeCalculation fun rangeTo(value: Long, other: Int) = value.rangeTo(other)
|
||||
@CompileTimeCalculation fun rangeTo(value: Long, other: Long) = value.rangeTo(other)
|
||||
|
||||
@CompileTimeCalculation fun shl(value: Long, bitCount: Int) = value.shl(bitCount)
|
||||
@CompileTimeCalculation fun shr(value: Long, bitCount: Int) = value.shr(bitCount)
|
||||
@CompileTimeCalculation fun ushr(value: Long, bitCount: Int) = value.ushr(bitCount)
|
||||
|
||||
@CompileTimeCalculation fun and(value: Long, other: Long) = value.and(other)
|
||||
@CompileTimeCalculation fun or(value: Long, other: Long) = value.or(other)
|
||||
@CompileTimeCalculation fun xor(value: Long, other: Long) = value.xor(other)
|
||||
@CompileTimeCalculation fun inv(value: Long) = value.inv()
|
||||
|
||||
@CompileTimeCalculation fun toByte(value: Long) = value.toByte()
|
||||
@CompileTimeCalculation fun toChar(value: Long) = value.toChar()
|
||||
@CompileTimeCalculation fun toShort(value: Long) = value.toShort()
|
||||
@CompileTimeCalculation fun toInt(value: Long) = value.toInt()
|
||||
@CompileTimeCalculation fun toLong(value: Long) = value.toLong()
|
||||
@CompileTimeCalculation fun toFloat(value: Long) = value.toFloat()
|
||||
@CompileTimeCalculation fun toDouble(value: Long) = value.toDouble()
|
||||
|
||||
@CompileTimeCalculation fun toString(value: Long) = value.toString()
|
||||
@CompileTimeCalculation fun hashCode(value: Long) = value.hashCode()
|
||||
@CompileTimeCalculation fun equals(value: Long, other: Long) = value.equals(other)
|
||||
|
||||
@CompileTimeCalculation fun echo(value: Any) = value
|
||||
|
||||
const val min = <!EVALUATED: `-9223372036854775808`!>echo(Long.MIN_VALUE) as Long<!>
|
||||
const val max = <!EVALUATED: `9223372036854775807`!>echo(Long.MAX_VALUE) as Long<!>
|
||||
const val bytes = <!EVALUATED: `8`!>echo(Long.SIZE_BYTES) as Int<!>
|
||||
const val bits = <!EVALUATED: `64`!>echo(Long.SIZE_BITS) as Int<!>
|
||||
|
||||
const val compare1 = <!EVALUATED: `1`!>compareTo(5L, 1.toByte())<!>
|
||||
const val compare2 = <!EVALUATED: `1`!>compareTo(5L, 2.toShort())<!>
|
||||
const val compare3 = <!EVALUATED: `1`!>compareTo(5L, 3)<!>
|
||||
const val compare4 = <!EVALUATED: `1`!>compareTo(5L, 4L)<!>
|
||||
const val compare5 = <!EVALUATED: `0`!>compareTo(5L, 5.toFloat())<!>
|
||||
const val compare6 = <!EVALUATED: `-1`!>compareTo(5L, 6.toDouble())<!>
|
||||
|
||||
const val plus1 = <!EVALUATED: `6`!>plus(5L, 1.toByte())<!>
|
||||
const val plus2 = <!EVALUATED: `7`!>plus(5L, 2.toShort())<!>
|
||||
const val plus3 = <!EVALUATED: `8`!>plus(5L, 3)<!>
|
||||
const val plus4 = <!EVALUATED: `9`!>plus(5L, 4L)<!>
|
||||
const val plus5 = <!EVALUATED: `10.0`!>plus(5L, 5.toFloat())<!>
|
||||
const val plus6 = <!EVALUATED: `11.0`!>plus(5L, 6.toDouble())<!>
|
||||
|
||||
const val minus1 = <!EVALUATED: `4`!>minus(5L, 1.toByte())<!>
|
||||
const val minus2 = <!EVALUATED: `3`!>minus(5L, 2.toShort())<!>
|
||||
const val minus3 = <!EVALUATED: `2`!>minus(5L, 3)<!>
|
||||
const val minus4 = <!EVALUATED: `1`!>minus(5L, 4L)<!>
|
||||
const val minus5 = <!EVALUATED: `0.0`!>minus(5L, 5.toFloat())<!>
|
||||
const val minus6 = <!EVALUATED: `-1.0`!>minus(5L, 6.toDouble())<!>
|
||||
|
||||
const val times1 = <!EVALUATED: `5`!>times(5L, 1.toByte())<!>
|
||||
const val times2 = <!EVALUATED: `10`!>times(5L, 2.toShort())<!>
|
||||
const val times3 = <!EVALUATED: `15`!>times(5L, 3)<!>
|
||||
const val times4 = <!EVALUATED: `20`!>times(5L, 4L)<!>
|
||||
const val times5 = <!EVALUATED: `25.0`!>times(5L, 5.toFloat())<!>
|
||||
const val times6 = <!EVALUATED: `30.0`!>times(5L, 6.toDouble())<!>
|
||||
|
||||
const val div1 = <!EVALUATED: `100`!>div(100L, 1.toByte())<!>
|
||||
const val div2 = <!EVALUATED: `50`!>div(100L, 2.toShort())<!>
|
||||
const val div3 = <!EVALUATED: `25`!>div(100L, 4)<!>
|
||||
const val div4 = <!EVALUATED: `10`!>div(100L, 10L)<!>
|
||||
const val div5 = <!EVALUATED: `4.0`!>div(100L, 25.toFloat())<!>
|
||||
const val div6 = <!EVALUATED: `2.0`!>div(100L, 50.toDouble())<!>
|
||||
|
||||
const val rem1 = <!EVALUATED: `0`!>rem(5L, 1.toByte())<!>
|
||||
const val rem2 = <!EVALUATED: `1`!>rem(5L, 2.toShort())<!>
|
||||
const val rem3 = <!EVALUATED: `2`!>rem(5L, 3)<!>
|
||||
const val rem4 = <!EVALUATED: `1`!>rem(5L, 4L)<!>
|
||||
const val rem5 = <!EVALUATED: `0.0`!>rem(5L, 5.toFloat())<!>
|
||||
const val rem6 = <!EVALUATED: `5.0`!>rem(5L, 6.toDouble())<!>
|
||||
|
||||
const val increment = <!EVALUATED: `4`!>inc(3L)<!>
|
||||
const val decrement = <!EVALUATED: `2`!>dec(3L)<!>
|
||||
|
||||
const val unaryPlus = <!EVALUATED: `3`!>unaryPlus(3L)<!>
|
||||
const val unaryMinus = <!EVALUATED: `-3`!>unaryMinus(3L)<!>
|
||||
|
||||
const val rangeTo1 = rangeTo(5L, 1.toByte()).<!EVALUATED: `1`!>last<!>
|
||||
const val rangeTo2 = rangeTo(5L, 2.toShort()).<!EVALUATED: `2`!>last<!>
|
||||
const val rangeTo3 = rangeTo(5L, 3).<!EVALUATED: `3`!>last<!>
|
||||
const val rangeTo4 = rangeTo(5L, 4L).<!EVALUATED: `4`!>last<!>
|
||||
|
||||
const val shiftLeft = <!EVALUATED: `16`!>shl(8L, 1)<!>
|
||||
const val shiftRight = <!EVALUATED: `2`!>shr(8L, 2)<!>
|
||||
const val unsignedShiftRight = <!EVALUATED: `2305843009213693951`!>ushr(-8L, 3)<!>
|
||||
|
||||
const val and = <!EVALUATED: `0`!>and(8L, 1L)<!>
|
||||
const val or = <!EVALUATED: `10`!>or(8L, 2L)<!>
|
||||
const val xor = <!EVALUATED: `-5`!>xor(-8L, 3L)<!>
|
||||
const val inv = <!EVALUATED: `-9`!>inv(8L)<!>
|
||||
|
||||
const val a1 = <!EVALUATED: `1`!>toByte(1L)<!>
|
||||
const val a2 = <!EVALUATED: ``!>toChar(2L)<!>
|
||||
const val a3 = <!EVALUATED: `3`!>toShort(3L)<!>
|
||||
const val a4 = <!EVALUATED: `4`!>toInt(4L)<!>
|
||||
const val a5 = <!EVALUATED: `5`!>toLong(5L)<!>
|
||||
const val a6 = <!EVALUATED: `6.0`!>toFloat(6L)<!>
|
||||
const val a7 = <!EVALUATED: `7.0`!>toDouble(7L)<!>
|
||||
|
||||
const val b1 = <!EVALUATED: `10`!>toString(10L)<!>
|
||||
const val b2 = <!EVALUATED: `10`!>hashCode(10L)<!>
|
||||
const val b3 = <!EVALUATED: `false`!>equals(10L, 11L)<!>
|
||||
const val b4 = <!EVALUATED: `true`!>equals(1L, 1.toLong())<!>
|
||||
const val b5 = <!EVALUATED: `true`!>equals(1L, 1)<!>
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
import kotlin.*
|
||||
|
||||
@CompileTimeCalculation fun compareTo(value: UInt, other: UByte) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: UInt, other: UShort) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: UInt, other: UInt) = value.compareTo(other)
|
||||
@CompileTimeCalculation fun compareTo(value: UInt, other: ULong) = value.compareTo(other)
|
||||
|
||||
@CompileTimeCalculation fun plus(value: UInt, other: UByte) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: UInt, other: UShort) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: UInt, other: UInt) = value.plus(other)
|
||||
@CompileTimeCalculation fun plus(value: UInt, other: ULong) = value.plus(other)
|
||||
|
||||
@CompileTimeCalculation fun minus(value: UInt, other: UByte) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: UInt, other: UShort) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: UInt, other: UInt) = value.minus(other)
|
||||
@CompileTimeCalculation fun minus(value: UInt, other: ULong) = value.minus(other)
|
||||
|
||||
@CompileTimeCalculation fun times(value: UInt, other: UByte) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: UInt, other: UShort) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: UInt, other: UInt) = value.times(other)
|
||||
@CompileTimeCalculation fun times(value: UInt, other: ULong) = value.times(other)
|
||||
|
||||
@CompileTimeCalculation fun div(value: UInt, other: UByte) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: UInt, other: UShort) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: UInt, other: UInt) = value.div(other)
|
||||
@CompileTimeCalculation fun div(value: UInt, other: ULong) = value.div(other)
|
||||
|
||||
@CompileTimeCalculation fun rem(value: UInt, other: UByte) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: UInt, other: UShort) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: UInt, other: UInt) = value.rem(other)
|
||||
@CompileTimeCalculation fun rem(value: UInt, other: ULong) = value.rem(other)
|
||||
|
||||
@CompileTimeCalculation fun inc(value: UInt) = value.inc()
|
||||
@CompileTimeCalculation fun dec(value: UInt) = value.dec()
|
||||
|
||||
@CompileTimeCalculation fun rangeTo(value: UInt, other: UInt) = value.rangeTo(other)
|
||||
|
||||
@CompileTimeCalculation fun shl(value: UInt, bitCount: Int) = value.shl(bitCount)
|
||||
@CompileTimeCalculation fun shr(value: UInt, bitCount: Int) = value.shr(bitCount)
|
||||
@CompileTimeCalculation fun and(value: UInt, other: UInt) = value.and(other)
|
||||
@CompileTimeCalculation fun or(value: UInt, other: UInt) = value.or(other)
|
||||
@CompileTimeCalculation fun xor(value: UInt, other: UInt) = value.xor(other)
|
||||
@CompileTimeCalculation fun inv(value: UInt) = value.inv()
|
||||
|
||||
@CompileTimeCalculation fun toByte(value: UInt) = value.toByte()
|
||||
@CompileTimeCalculation fun toShort(value: UInt) = value.toShort()
|
||||
@CompileTimeCalculation fun toInt(value: UInt) = value.toInt()
|
||||
@CompileTimeCalculation fun toLong(value: UInt) = value.toLong()
|
||||
@CompileTimeCalculation fun toUByte(value: UInt) = value.toUByte()
|
||||
@CompileTimeCalculation fun toUShort(value: UInt) = value.toUShort()
|
||||
@CompileTimeCalculation fun toUInt(value: UInt) = value.toUInt()
|
||||
@CompileTimeCalculation fun toULong(value: UInt) = value.toULong()
|
||||
@CompileTimeCalculation fun toFloat(value: UInt) = value.toFloat()
|
||||
@CompileTimeCalculation fun toDouble(value: UInt) = value.toDouble()
|
||||
|
||||
@CompileTimeCalculation fun toString(value: UInt) = value.toString()
|
||||
@CompileTimeCalculation fun hashCode(value: UInt) = value.hashCode()
|
||||
@CompileTimeCalculation fun equals(value: UInt, other: Any) = value.equals(other)
|
||||
|
||||
@CompileTimeCalculation fun echo(value: Any) = value
|
||||
|
||||
const val min = <!EVALUATED: `0`!>echo(UInt.MIN_VALUE) as UInt<!>
|
||||
const val max = <!EVALUATED: `-1`!>echo(UInt.MAX_VALUE) as UInt<!>
|
||||
const val bytes = <!EVALUATED: `4`!>echo(UInt.SIZE_BYTES) as Int<!>
|
||||
const val bits = <!EVALUATED: `32`!>echo(UInt.SIZE_BITS) as Int<!>
|
||||
|
||||
const val uByte: UByte = 0u
|
||||
const val uByteNonZero: UByte = 1u
|
||||
const val uShort: UShort = 1u
|
||||
const val uInt: UInt = 2u
|
||||
const val uLong: ULong = 3uL
|
||||
|
||||
const val compare1 = <!EVALUATED: `1`!>compareTo(2u, uByte)<!>
|
||||
const val compare2 = <!EVALUATED: `1`!>compareTo(2u, uShort)<!>
|
||||
const val compare3 = <!EVALUATED: `0`!>compareTo(2u, uInt)<!>
|
||||
const val compare4 = <!EVALUATED: `-1`!>compareTo(2u, uLong)<!>
|
||||
|
||||
const val plus1 = <!EVALUATED: `2`!>plus(2u, uByte)<!>
|
||||
const val plus2 = <!EVALUATED: `3`!>plus(2u, uShort)<!>
|
||||
const val plus3 = <!EVALUATED: `4`!>plus(2u, uInt)<!>
|
||||
const val plus4 = <!EVALUATED: `5`!>plus(2u, uLong)<!>
|
||||
|
||||
const val minus1 = <!EVALUATED: `2`!>minus(2u, uByte)<!>
|
||||
const val minus2 = <!EVALUATED: `1`!>minus(2u, uShort)<!>
|
||||
const val minus3 = <!EVALUATED: `0`!>minus(2u, uInt)<!>
|
||||
const val minus4 = <!EVALUATED: `-1`!>minus(2u, uLong)<!>
|
||||
|
||||
const val times1 = <!EVALUATED: `0`!>times(2u, uByte)<!>
|
||||
const val times2 = <!EVALUATED: `2`!>times(2u, uShort)<!>
|
||||
const val times3 = <!EVALUATED: `4`!>times(2u, uInt)<!>
|
||||
const val times4 = <!EVALUATED: `6`!>times(2u, uLong)<!>
|
||||
|
||||
const val div1 = <!EVALUATED: `2`!>div(2u, uByteNonZero)<!>
|
||||
const val div2 = <!EVALUATED: `2`!>div(2u, uShort)<!>
|
||||
const val div3 = <!EVALUATED: `1`!>div(2u, uInt)<!>
|
||||
const val div4 = <!EVALUATED: `0`!>div(2u, uLong)<!>
|
||||
|
||||
const val rem1 = <!EVALUATED: `0`!>rem(2u, uByteNonZero)<!>
|
||||
const val rem2 = <!EVALUATED: `0`!>rem(2u, uShort)<!>
|
||||
const val rem3 = <!EVALUATED: `0`!>rem(2u, uInt)<!>
|
||||
const val rem4 = <!EVALUATED: `2`!>rem(2u, uLong)<!>
|
||||
|
||||
const val inc = <!EVALUATED: `4`!>inc(3u)<!>
|
||||
const val dec = <!EVALUATED: `2`!>dec(3u)<!>
|
||||
|
||||
const val rangeTo = rangeTo(0u, 10u).<!EVALUATED: `10`!>last<!>
|
||||
|
||||
const val shiftLeft = <!EVALUATED: `16`!>shl(8u, 1)<!>
|
||||
const val shiftRight = <!EVALUATED: `2`!>shr(8u, 2)<!>
|
||||
|
||||
const val and = <!EVALUATED: `0`!>and(8u, 1u)<!>
|
||||
const val or = <!EVALUATED: `10`!>or(8u, 2u)<!>
|
||||
const val xor = <!EVALUATED: `11`!>xor(8u, 3u)<!>
|
||||
const val inv = <!EVALUATED: `-9`!>inv(8u)<!>
|
||||
|
||||
const val a1 = <!EVALUATED: `1`!>toByte(1u)<!>
|
||||
const val a2 = <!EVALUATED: `2`!>toShort(2u)<!>
|
||||
const val a3 = <!EVALUATED: `3`!>toInt(3u)<!>
|
||||
const val a4 = <!EVALUATED: `4`!>toLong(4u)<!>
|
||||
const val a5 = <!EVALUATED: `5`!>toUByte(5u)<!>
|
||||
const val a6 = <!EVALUATED: `6`!>toUShort(6u)<!>
|
||||
const val a7 = <!EVALUATED: `7`!>toUInt(7u)<!>
|
||||
const val a8 = <!EVALUATED: `8`!>toULong(8u)<!>
|
||||
const val a9 = <!EVALUATED: `9.0`!>toFloat(9u)<!>
|
||||
const val a10 = <!EVALUATED: `10.0`!>toDouble(10u)<!>
|
||||
|
||||
const val b1 = <!EVALUATED: `10`!>toString(10u)<!>
|
||||
// const val b2 = hashCode(10u) TODO support later; in current version method hashCode is missing
|
||||
const val b3 = <!EVALUATED: `false`!>equals(10u, 11u)<!>
|
||||
const val b4 = <!EVALUATED: `false`!>equals(1u, 1)<!>
|
||||
const val b5 = <!EVALUATED: `false`!>equals(3u, 3uL)<!>
|
||||
@@ -0,0 +1,3 @@
|
||||
const val a = IntProgression.fromClosedRange(0, 10, 1).<!EVALUATED: `0`!>first<!>
|
||||
const val b = LongProgression.fromClosedRange(0L, 10L, 1L).<!EVALUATED: `10`!>last<!>
|
||||
const val c = CharProgression.fromClosedRange('0', '9', 1).<!EVALUATED: `1`!>step<!>
|
||||
@@ -0,0 +1,12 @@
|
||||
@CompileTimeCalculation
|
||||
class MyCharSequence(val str: String): CharSequence {
|
||||
override val length: Int = str.length
|
||||
|
||||
override fun get(index: Int) = str[index]
|
||||
|
||||
override fun subSequence(startIndex: Int, endIndex: Int) = str.subSequence(startIndex, endIndex)
|
||||
}
|
||||
|
||||
const val sbSize = StringBuilder(MyCharSequence("MyString")).<!EVALUATED: `8`!>length<!>
|
||||
const val appendSize = StringBuilder().append(MyCharSequence("MyString")).<!EVALUATED: `8`!>length<!>
|
||||
const val subSequenceSize = StringBuilder(StringBuilder(MyCharSequence("MyString")).subSequence(0, 4)).<!EVALUATED: `4`!>length<!>
|
||||
@@ -0,0 +1,13 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
class B(val b: Int) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
other as? B ?: return false
|
||||
return this.b == other.b
|
||||
}
|
||||
|
||||
override fun toString(): String = "B($b)"
|
||||
}
|
||||
const val areEquals = <!EVALUATED: `true`!>listOf(B(1), B(2)) == listOf(B(1), B(2))<!>
|
||||
const val asString = listOf(B(1), B(2)).<!EVALUATED: `[B(1), B(2)]`!>toString()<!>
|
||||
@@ -0,0 +1,8 @@
|
||||
import kotlin.*
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
class A(val a: Int)
|
||||
const val size = mapOf(1 to "A(1)").<!EVALUATED: `1`!>size<!>
|
||||
const val first = mapOf(1 to "A(1)").entries.single().<!EVALUATED: `1`!>key<!>
|
||||
const val second = mapOf(1 to "A(1)").values.<!EVALUATED: `A(1)`!>single()<!>
|
||||
@@ -0,0 +1,21 @@
|
||||
import kotlin.collections.*
|
||||
|
||||
@CompileTimeCalculation
|
||||
class MyArrayList<E>: ArrayList<E>() {
|
||||
var addCounter = 0
|
||||
override fun add(element: E): Boolean {
|
||||
addCounter++
|
||||
return super.add(element)
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun test(): String {
|
||||
val list = MyArrayList<Int>()
|
||||
list.add(1)
|
||||
list.add(2)
|
||||
list.add(3)
|
||||
return "Counter " + list.addCounter + "; size " + list.size
|
||||
}
|
||||
|
||||
const val testResult = <!EVALUATED: `Counter 3; size 3`!>test()<!>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user