diff --git a/compiler/testData/psi/FunctionWithMultilineContract.kt b/compiler/testData/psi/contracts/FunctionWithMultilineContract.kt similarity index 100% rename from compiler/testData/psi/FunctionWithMultilineContract.kt rename to compiler/testData/psi/contracts/FunctionWithMultilineContract.kt diff --git a/compiler/testData/psi/FunctionWithMultilineContract.txt b/compiler/testData/psi/contracts/FunctionWithMultilineContract.txt similarity index 100% rename from compiler/testData/psi/FunctionWithMultilineContract.txt rename to compiler/testData/psi/contracts/FunctionWithMultilineContract.txt diff --git a/compiler/testData/psi/FunctionsWithTypeConstraintsAndContract.kt b/compiler/testData/psi/contracts/FunctionsWithTypeConstraintsAndContract.kt similarity index 100% rename from compiler/testData/psi/FunctionsWithTypeConstraintsAndContract.kt rename to compiler/testData/psi/contracts/FunctionsWithTypeConstraintsAndContract.kt diff --git a/compiler/testData/psi/FunctionsWithTypeConstraintsAndContract.txt b/compiler/testData/psi/contracts/FunctionsWithTypeConstraintsAndContract.txt similarity index 100% rename from compiler/testData/psi/FunctionsWithTypeConstraintsAndContract.txt rename to compiler/testData/psi/contracts/FunctionsWithTypeConstraintsAndContract.txt diff --git a/compiler/testData/psi/contracts/PropertyAccessorsContracts.kt b/compiler/testData/psi/contracts/PropertyAccessorsContracts.kt new file mode 100644 index 00000000000..e7dc87e7eb0 --- /dev/null +++ b/compiler/testData/psi/contracts/PropertyAccessorsContracts.kt @@ -0,0 +1,24 @@ +class MyClass { + var myInt: Int = 0 + get() contract [returnsNotNull()] = 1 + set(value) { + field = value * 10 + } +} + +class AnotherClass(multiplier: Int) { + var anotherInt: Int = 0 + get() contract [returnsNotNull()] = 1 + set(value) contract [returns()] { + field = value * multiplier + } +} + +class SomeClass(multiplier: Int?) { + var someInt: Int = 0 + get() contract [returnsNotNull()] = 1 + set(value) contract [returns() implies (value != null)] { + value ?: throw NullArgumentException() + field = value + } +} \ No newline at end of file diff --git a/compiler/testData/psi/contracts/PropertyAccessorsContracts.txt b/compiler/testData/psi/contracts/PropertyAccessorsContracts.txt new file mode 100644 index 00000000000..0db353c86fc --- /dev/null +++ b/compiler/testData/psi/contracts/PropertyAccessorsContracts.txt @@ -0,0 +1,320 @@ +KtFile: PropertyAccessorsContracts.kt + PACKAGE_DIRECTIVE + + IMPORT_LIST + + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('MyClass') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('myInt') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('0') + PsiWhiteSpace('\n ') + PROPERTY_ACCESSOR + PsiElement(get)('get') + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(contract)('contract') + PsiWhiteSpace(' ') + CONTRACT_EFFECT_LIST + PsiElement(LBRACKET)('[') + CONTRACT_EFFECT + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('returnsNotNull') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n ') + PROPERTY_ACCESSOR + PsiElement(set)('set') + PsiElement(LPAR)('(') + VALUE_PARAMETER_LIST + VALUE_PARAMETER + PsiElement(IDENTIFIER)('value') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('field') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('value') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('10') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('AnotherClass') + PRIMARY_CONSTRUCTOR + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('multiplier') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('anotherInt') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('0') + PsiWhiteSpace('\n ') + PROPERTY_ACCESSOR + PsiElement(get)('get') + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(contract)('contract') + PsiWhiteSpace(' ') + CONTRACT_EFFECT_LIST + PsiElement(LBRACKET)('[') + CONTRACT_EFFECT + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('returnsNotNull') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n ') + PROPERTY_ACCESSOR + PsiElement(set)('set') + PsiElement(LPAR)('(') + VALUE_PARAMETER_LIST + VALUE_PARAMETER + PsiElement(IDENTIFIER)('value') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(contract)('contract') + PsiWhiteSpace(' ') + CONTRACT_EFFECT_LIST + PsiElement(LBRACKET)('[') + CONTRACT_EFFECT + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('returns') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('field') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('value') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('multiplier') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('SomeClass') + PRIMARY_CONSTRUCTOR + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('multiplier') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + NULLABLE_TYPE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(QUEST)('?') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('someInt') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('0') + PsiWhiteSpace('\n ') + PROPERTY_ACCESSOR + PsiElement(get)('get') + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(contract)('contract') + PsiWhiteSpace(' ') + CONTRACT_EFFECT_LIST + PsiElement(LBRACKET)('[') + CONTRACT_EFFECT + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('returnsNotNull') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n ') + PROPERTY_ACCESSOR + PsiElement(set)('set') + PsiElement(LPAR)('(') + VALUE_PARAMETER_LIST + VALUE_PARAMETER + PsiElement(IDENTIFIER)('value') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(contract)('contract') + PsiWhiteSpace(' ') + CONTRACT_EFFECT_LIST + PsiElement(LBRACKET)('[') + CONTRACT_EFFECT + BINARY_EXPRESSION + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('returns') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(IDENTIFIER)('implies') + PsiWhiteSpace(' ') + PARENTHESIZED + PsiElement(LPAR)('(') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('value') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(EXCLEQ)('!=') + PsiWhiteSpace(' ') + NULL + PsiElement(null)('null') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('value') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(ELVIS)('?:') + PsiWhiteSpace(' ') + THROW + PsiElement(throw)('throw') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('NullArgumentException') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('field') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('value') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/SimpleFunctionWithContract.kt b/compiler/testData/psi/contracts/SimpleFunctionWithContract.kt similarity index 100% rename from compiler/testData/psi/SimpleFunctionWithContract.kt rename to compiler/testData/psi/contracts/SimpleFunctionWithContract.kt diff --git a/compiler/testData/psi/SimpleFunctionWithContract.txt b/compiler/testData/psi/contracts/SimpleFunctionWithContract.txt similarity index 100% rename from compiler/testData/psi/SimpleFunctionWithContract.txt rename to compiler/testData/psi/contracts/SimpleFunctionWithContract.txt diff --git a/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java index 0e6430d93e6..6a44d5f73e1 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java @@ -380,21 +380,11 @@ public class ParsingTestGenerated extends AbstractParsingTest { runTest("compiler/testData/psi/FunctionTypes.kt"); } - @TestMetadata("FunctionWithMultilineContract.kt") - public void testFunctionWithMultilineContract() throws Exception { - runTest("compiler/testData/psi/FunctionWithMultilineContract.kt"); - } - @TestMetadata("Functions.kt") public void testFunctions() throws Exception { runTest("compiler/testData/psi/Functions.kt"); } - @TestMetadata("FunctionsWithTypeConstraintsAndContract.kt") - public void testFunctionsWithTypeConstraintsAndContract() throws Exception { - runTest("compiler/testData/psi/FunctionsWithTypeConstraintsAndContract.kt"); - } - @TestMetadata("FunctionsWithoutName.kt") public void testFunctionsWithoutName() throws Exception { runTest("compiler/testData/psi/FunctionsWithoutName.kt"); @@ -630,11 +620,6 @@ public class ParsingTestGenerated extends AbstractParsingTest { runTest("compiler/testData/psi/SimpleExpressions.kt"); } - @TestMetadata("SimpleFunctionWithContract.kt") - public void testSimpleFunctionWithContract() throws Exception { - runTest("compiler/testData/psi/SimpleFunctionWithContract.kt"); - } - @TestMetadata("SimpleModifiers.kt") public void testSimpleModifiers() throws Exception { runTest("compiler/testData/psi/SimpleModifiers.kt"); @@ -1277,6 +1262,39 @@ public class ParsingTestGenerated extends AbstractParsingTest { } } + @TestMetadata("compiler/testData/psi/contracts") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Contracts extends AbstractParsingTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doParsingTest, this, testDataFilePath); + } + + public void testAllFilesPresentInContracts() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/psi/contracts"), Pattern.compile("^(.*)\\.kts?$"), null, true); + } + + @TestMetadata("FunctionWithMultilineContract.kt") + public void testFunctionWithMultilineContract() throws Exception { + runTest("compiler/testData/psi/contracts/FunctionWithMultilineContract.kt"); + } + + @TestMetadata("FunctionsWithTypeConstraintsAndContract.kt") + public void testFunctionsWithTypeConstraintsAndContract() throws Exception { + runTest("compiler/testData/psi/contracts/FunctionsWithTypeConstraintsAndContract.kt"); + } + + @TestMetadata("PropertyAccessorsContracts.kt") + public void testPropertyAccessorsContracts() throws Exception { + runTest("compiler/testData/psi/contracts/PropertyAccessorsContracts.kt"); + } + + @TestMetadata("SimpleFunctionWithContract.kt") + public void testSimpleFunctionWithContract() throws Exception { + runTest("compiler/testData/psi/contracts/SimpleFunctionWithContract.kt"); + } + } + @TestMetadata("compiler/testData/psi/examples") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)