diff --git a/.classpath b/.classpath index 49737c980..7e3e107a9 100644 --- a/.classpath +++ b/.classpath @@ -62,6 +62,13 @@ + + + + + + + diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 000000000..cf3903c6e --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,14 @@ +;;; Directory Local Variables +;;; For more information see (info "(emacs) Directory Variables") + +((java-mode . ((tab-width . 8) + (c-basic-offset . 8) + (indent-tabs-mode . t) + (ws-trim-mode . t) + (eval . (progn + (c-set-offset 'arglist-cont-nonempty '++) + (c-set-offset 'case-label '+))))) + (protobuf-mode . ((tab-width . 8) + (c-basic-offset . 8) + (indent-tabs-mode . t) + (ws-trim-mode . t)))) diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index a9355b66c..c0af9e89f 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -90,6 +90,19 @@ jobs: - name: Run unit tests - datagen - Java run: ant -noinput -buildfile build.xml -Dprotobuf.uptodate=true test-datagen-java + test-datagen-kotlin: + needs: compile + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'temurin' + - name: Run unit tests - datagen - Kotlin + run: ant -noinput -buildfile build.xml -Dprotobuf.uptodate=true test-datagen-kotlin + test-datagen-js: needs: compile runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 63bd8b72b..6ca625105 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /junitvmwatcher*.properties .vscode/ /src/antlr/.antlr +.*.swp diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..023a43408 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/boa.bat b/boa.bat index 34f3b3b2f..0e6e977d1 100644 --- a/boa.bat +++ b/boa.bat @@ -1,4 +1,4 @@ @ECHO OFF -"%JAVA_HOME%"\bin\java -cp .;"%~dp0dist\boa-compiler.jar";"%~dp0lib\*";"%~dp0lib\evaluator\*";"%~dp0lib\datagen\*";"%~dp0compile" boa.BoaMain %* +"%JAVA_HOME%"\bin\java -cp .;"%~dp0dist\boa-compiler.jar";"%~dp0lib\*";"%~dp0lib\evaluator\*";"%~dp0lib\datagen\*";"%~dp0lib\datagen-kotlin\*";"%~dp0compile" boa.BoaMain %* pause diff --git a/boa.sh b/boa.sh index 5122d8262..f321b889e 100755 --- a/boa.sh +++ b/boa.sh @@ -1,5 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash BASEDIR=$(dirname "$0") -java -cp ".:$BASEDIR/dist/boa-compiler.jar:$BASEDIR/lib/*:$BASEDIR/lib/evaluator/*:$BASEDIR/lib/datagen/*:$BASEDIR/compile" boa.BoaMain $* +java -cp ".:$BASEDIR/dist/boa-compiler.jar:$BASEDIR/lib/*:$BASEDIR/lib/evaluator/*:$BASEDIR/lib/datagen/*:$BASEDIR/lib/datagen-kotlin/*:$BASEDIR/compile" boa.BoaMain $* diff --git a/build.xml b/build.xml index 10f737cdf..bc50a95c7 100644 --- a/build.xml +++ b/build.xml @@ -261,6 +261,21 @@ + + + + + + + + + + + + + + + @@ -447,20 +462,36 @@ - + - + + + + + + + + + + + + + + + + + @@ -473,10 +504,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + +
+ + + +
+
@@ -487,13 +555,28 @@ + + + + + + +
- + + + + +
+ + + +
diff --git a/evaluate.sh b/evaluate.sh index 56eaa2e0e..074bd5e46 100755 --- a/evaluate.sh +++ b/evaluate.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if [ "$#" -lt 2 ]; then echo "Usage: $0 file.boa output-dir/ [options]" diff --git a/lib/datagen-kotlin/annotations-21.0.1.jar b/lib/datagen-kotlin/annotations-21.0.1.jar new file mode 100644 index 000000000..4ffcd1772 Binary files /dev/null and b/lib/datagen-kotlin/annotations-21.0.1.jar differ diff --git a/lib/datagen-kotlin/kotlin-compiler-1.5.20.jar b/lib/datagen-kotlin/kotlin-compiler-1.5.20.jar new file mode 100644 index 000000000..8b41bfa3b Binary files /dev/null and b/lib/datagen-kotlin/kotlin-compiler-1.5.20.jar differ diff --git a/lib/datagen-kotlin/kotlin-reflect-1.5.20.jar b/lib/datagen-kotlin/kotlin-reflect-1.5.20.jar new file mode 100644 index 000000000..1d16a63cb Binary files /dev/null and b/lib/datagen-kotlin/kotlin-reflect-1.5.20.jar differ diff --git a/lib/datagen-kotlin/kotlin-script-runtime-1.5.20.jar b/lib/datagen-kotlin/kotlin-script-runtime-1.5.20.jar new file mode 100644 index 000000000..abd06087b Binary files /dev/null and b/lib/datagen-kotlin/kotlin-script-runtime-1.5.20.jar differ diff --git a/lib/datagen-kotlin/kotlin-stdlib-1.5.20.jar b/lib/datagen-kotlin/kotlin-stdlib-1.5.20.jar new file mode 100644 index 000000000..e87e68c36 Binary files /dev/null and b/lib/datagen-kotlin/kotlin-stdlib-1.5.20.jar differ diff --git a/lib/datagen-kotlin/openapi-7.0.3.jar b/lib/datagen-kotlin/openapi-7.0.3.jar new file mode 100644 index 000000000..6713990f4 Binary files /dev/null and b/lib/datagen-kotlin/openapi-7.0.3.jar differ diff --git a/lib/datagen-kotlin/trove4j-1.0.20200330.jar b/lib/datagen-kotlin/trove4j-1.0.20200330.jar new file mode 100644 index 000000000..0b174bffd Binary files /dev/null and b/lib/datagen-kotlin/trove4j-1.0.20200330.jar differ diff --git a/src/compiled-proto/boa/types/Ast.java b/src/compiled-proto/boa/types/Ast.java index 15841f2ab..1f646ea1b 100644 --- a/src/compiled-proto/boa/types/Ast.java +++ b/src/compiled-proto/boa/types/Ast.java @@ -113,6 +113,46 @@ public enum TypeKind * */ ARRAY(13, 11), + /** + * IMMUTABLE = 12; + * + *
+     ** Immutable data type 
+     * 
+ */ + IMMUTABLE(14, 12), + /** + * ALIAS = 13; + * + *
+     ** A typedef/alias 
+     * 
+ */ + ALIAS(15, 13), + /** + * SINGLETON = 14; + * + *
+     ** Types declared as a singletons 
+     * 
+ */ + SINGLETON(16, 14), + /** + * DYNAMIC = 15; + * + *
+     ** Types declared as explicitly dynamic 
+     * 
+ */ + DYNAMIC(17, 15), + /** + * DELEGATED = 16; + * + *
+     ** A delegated type 
+     * 
+ */ + DELEGATED(18, 16), ; /** @@ -243,6 +283,46 @@ public enum TypeKind * */ public static final int ARRAY_VALUE = 11; + /** + * IMMUTABLE = 12; + * + *
+     ** Immutable data type 
+     * 
+ */ + public static final int IMMUTABLE_VALUE = 12; + /** + * ALIAS = 13; + * + *
+     ** A typedef/alias 
+     * 
+ */ + public static final int ALIAS_VALUE = 13; + /** + * SINGLETON = 14; + * + *
+     ** Types declared as a singletons 
+     * 
+ */ + public static final int SINGLETON_VALUE = 14; + /** + * DYNAMIC = 15; + * + *
+     ** Types declared as explicitly dynamic 
+     * 
+ */ + public static final int DYNAMIC_VALUE = 15; + /** + * DELEGATED = 16; + * + *
+     ** A delegated type 
+     * 
+ */ + public static final int DELEGATED_VALUE = 16; public final int getNumber() { return value; } @@ -261,6 +341,11 @@ public static TypeKind valueOf(int value) { case 9: return TRAIT; case 10: return PRIMITIVE; case 11: return ARRAY; + case 12: return IMMUTABLE; + case 13: return ALIAS; + case 14: return SINGLETON; + case 15: return DYNAMIC; + case 16: return DELEGATED; default: return null; } } @@ -291,7 +376,7 @@ public TypeKind findValueByNumber(int number) { } private static final TypeKind[] VALUES = { - OTHER, CLASS, INTERFACE, ANONYMOUS, ANON, STRUCT, ENUM, ENUMERATION, ANNOTATION, DELEGATE, GENERIC, TRAIT, PRIMITIVE, ARRAY, + OTHER, CLASS, INTERFACE, ANONYMOUS, ANON, STRUCT, ENUM, ENUMERATION, ANNOTATION, DELEGATE, GENERIC, TRAIT, PRIMITIVE, ARRAY, IMMUTABLE, ALIAS, SINGLETON, DYNAMIC, DELEGATED, }; public static TypeKind valueOf( @@ -11790,6 +11875,32 @@ public interface TypeOrBuilder * optional .boa.types.Expression computed_name = 14; */ boa.types.Ast.ExpressionOrBuilder getComputedNameOrBuilder(); + + // optional .boa.types.Expression delegate = 15; + /** + * optional .boa.types.Expression delegate = 15; + * + *
+     ** For delegated types, this is the expression to delegate to. 
+     * 
+ */ + boolean hasDelegate(); + /** + * optional .boa.types.Expression delegate = 15; + * + *
+     ** For delegated types, this is the expression to delegate to. 
+     * 
+ */ + boa.types.Ast.Expression getDelegate(); + /** + * optional .boa.types.Expression delegate = 15; + * + *
+     ** For delegated types, this is the expression to delegate to. 
+     * 
+ */ + boa.types.Ast.ExpressionOrBuilder getDelegateOrBuilder(); } /** * Protobuf type {@code boa.types.Type} @@ -11900,6 +12011,19 @@ private Type( bitField0_ |= 0x00000080; break; } + case 122: { + boa.types.Ast.Expression.Builder subBuilder = null; + if (((bitField0_ & 0x00000100) == 0x00000100)) { + subBuilder = delegate_.toBuilder(); + } + delegate_ = input.readMessage(boa.types.Ast.Expression.PARSER, extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom(delegate_); + delegate_ = subBuilder.buildPartial(); + } + bitField0_ |= 0x00000100; + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -12223,6 +12347,40 @@ public boa.types.Ast.ExpressionOrBuilder getComputedNameOrBuilder() { return computedName_; } + // optional .boa.types.Expression delegate = 15; + public static final int DELEGATE_FIELD_NUMBER = 15; + private boa.types.Ast.Expression delegate_; + /** + * optional .boa.types.Expression delegate = 15; + * + *
+     ** For delegated types, this is the expression to delegate to. 
+     * 
+ */ + public boolean hasDelegate() { + return ((bitField0_ & 0x00000100) == 0x00000100); + } + /** + * optional .boa.types.Expression delegate = 15; + * + *
+     ** For delegated types, this is the expression to delegate to. 
+     * 
+ */ + public boa.types.Ast.Expression getDelegate() { + return delegate_; + } + /** + * optional .boa.types.Expression delegate = 15; + * + *
+     ** For delegated types, this is the expression to delegate to. 
+     * 
+ */ + public boa.types.Ast.ExpressionOrBuilder getDelegateOrBuilder() { + return delegate_; + } + private void initFields() { name_ = ""; fullyQualifiedName_ = ""; @@ -12232,6 +12390,7 @@ private void initFields() { declaration_ = 0; key_ = 0; computedName_ = boa.types.Ast.Expression.getDefaultInstance(); + delegate_ = boa.types.Ast.Expression.getDefaultInstance(); } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -12248,6 +12407,12 @@ public final boolean isInitialized() { return false; } } + if (hasDelegate()) { + if (!getDelegate().isInitialized()) { + memoizedIsInitialized = 0; + return false; + } + } memoizedIsInitialized = 1; return true; } @@ -12279,6 +12444,9 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (((bitField0_ & 0x00000080) == 0x00000080)) { output.writeMessage(14, computedName_); } + if (((bitField0_ & 0x00000100) == 0x00000100)) { + output.writeMessage(15, delegate_); + } getUnknownFields().writeTo(output); } @@ -12320,6 +12488,10 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeMessageSize(14, computedName_); } + if (((bitField0_ & 0x00000100) == 0x00000100)) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(15, delegate_); + } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; @@ -12433,6 +12605,7 @@ private Builder( private void maybeForceBuilderInitialization() { if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { getComputedNameFieldBuilder(); + getDelegateFieldBuilder(); } } private static Builder create() { @@ -12461,6 +12634,12 @@ public Builder clear() { computedNameBuilder_.clear(); } bitField0_ = (bitField0_ & ~0x00000080); + if (delegateBuilder_ == null) { + delegate_ = boa.types.Ast.Expression.getDefaultInstance(); + } else { + delegateBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000100); return this; } @@ -12525,6 +12704,14 @@ public boa.types.Ast.Type buildPartial() { } else { result.computedName_ = computedNameBuilder_.build(); } + if (((from_bitField0_ & 0x00000100) == 0x00000100)) { + to_bitField0_ |= 0x00000100; + } + if (delegateBuilder_ == null) { + result.delegate_ = delegate_; + } else { + result.delegate_ = delegateBuilder_.build(); + } result.bitField0_ = to_bitField0_; onBuilt(); return result; @@ -12571,6 +12758,9 @@ public Builder mergeFrom(boa.types.Ast.Type other) { if (other.hasComputedName()) { mergeComputedName(other.getComputedName()); } + if (other.hasDelegate()) { + mergeDelegate(other.getDelegate()); + } this.mergeUnknownFields(other.getUnknownFields()); return this; } @@ -12586,6 +12776,12 @@ public final boolean isInitialized() { return false; } } + if (hasDelegate()) { + if (!getDelegate().isInitialized()) { + + return false; + } + } return true; } @@ -13218,6 +13414,159 @@ public boa.types.Ast.ExpressionOrBuilder getComputedNameOrBuilder() { return computedNameBuilder_; } + // optional .boa.types.Expression delegate = 15; + private boa.types.Ast.Expression delegate_ = boa.types.Ast.Expression.getDefaultInstance(); + private com.google.protobuf.SingleFieldBuilder< + boa.types.Ast.Expression, boa.types.Ast.Expression.Builder, boa.types.Ast.ExpressionOrBuilder> delegateBuilder_; + /** + * optional .boa.types.Expression delegate = 15; + * + *
+       ** For delegated types, this is the expression to delegate to. 
+       * 
+ */ + public boolean hasDelegate() { + return ((bitField0_ & 0x00000100) == 0x00000100); + } + /** + * optional .boa.types.Expression delegate = 15; + * + *
+       ** For delegated types, this is the expression to delegate to. 
+       * 
+ */ + public boa.types.Ast.Expression getDelegate() { + if (delegateBuilder_ == null) { + return delegate_; + } else { + return delegateBuilder_.getMessage(); + } + } + /** + * optional .boa.types.Expression delegate = 15; + * + *
+       ** For delegated types, this is the expression to delegate to. 
+       * 
+ */ + public Builder setDelegate(boa.types.Ast.Expression value) { + if (delegateBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + delegate_ = value; + onChanged(); + } else { + delegateBuilder_.setMessage(value); + } + bitField0_ |= 0x00000100; + return this; + } + /** + * optional .boa.types.Expression delegate = 15; + * + *
+       ** For delegated types, this is the expression to delegate to. 
+       * 
+ */ + public Builder setDelegate( + boa.types.Ast.Expression.Builder builderForValue) { + if (delegateBuilder_ == null) { + delegate_ = builderForValue.build(); + onChanged(); + } else { + delegateBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000100; + return this; + } + /** + * optional .boa.types.Expression delegate = 15; + * + *
+       ** For delegated types, this is the expression to delegate to. 
+       * 
+ */ + public Builder mergeDelegate(boa.types.Ast.Expression value) { + if (delegateBuilder_ == null) { + if (((bitField0_ & 0x00000100) == 0x00000100) && + delegate_ != boa.types.Ast.Expression.getDefaultInstance()) { + delegate_ = + boa.types.Ast.Expression.newBuilder(delegate_).mergeFrom(value).buildPartial(); + } else { + delegate_ = value; + } + onChanged(); + } else { + delegateBuilder_.mergeFrom(value); + } + bitField0_ |= 0x00000100; + return this; + } + /** + * optional .boa.types.Expression delegate = 15; + * + *
+       ** For delegated types, this is the expression to delegate to. 
+       * 
+ */ + public Builder clearDelegate() { + if (delegateBuilder_ == null) { + delegate_ = boa.types.Ast.Expression.getDefaultInstance(); + onChanged(); + } else { + delegateBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000100); + return this; + } + /** + * optional .boa.types.Expression delegate = 15; + * + *
+       ** For delegated types, this is the expression to delegate to. 
+       * 
+ */ + public boa.types.Ast.Expression.Builder getDelegateBuilder() { + bitField0_ |= 0x00000100; + onChanged(); + return getDelegateFieldBuilder().getBuilder(); + } + /** + * optional .boa.types.Expression delegate = 15; + * + *
+       ** For delegated types, this is the expression to delegate to. 
+       * 
+ */ + public boa.types.Ast.ExpressionOrBuilder getDelegateOrBuilder() { + if (delegateBuilder_ != null) { + return delegateBuilder_.getMessageOrBuilder(); + } else { + return delegate_; + } + } + /** + * optional .boa.types.Expression delegate = 15; + * + *
+       ** For delegated types, this is the expression to delegate to. 
+       * 
+ */ + private com.google.protobuf.SingleFieldBuilder< + boa.types.Ast.Expression, boa.types.Ast.Expression.Builder, boa.types.Ast.ExpressionOrBuilder> + getDelegateFieldBuilder() { + if (delegateBuilder_ == null) { + delegateBuilder_ = new com.google.protobuf.SingleFieldBuilder< + boa.types.Ast.Expression, boa.types.Ast.Expression.Builder, boa.types.Ast.ExpressionOrBuilder>( + delegate_, + getParentForChildren(), + isClean()); + delegate_ = null; + } + return delegateBuilder_; + } + // @@protoc_insertion_point(builder_scope:boa.types.Type) } @@ -13631,6 +13980,58 @@ boa.types.Ast.CommentOrBuilder getCommentsOrBuilder( * */ boa.types.Ast.ExpressionOrBuilder getComputedNameOrBuilder(); + + // optional .boa.types.Expression expression = 15; + /** + * optional .boa.types.Expression expression = 15; + * + *
+     ** The method body expression, if the body is not composed of statements. 
+     * 
+ */ + boolean hasExpression(); + /** + * optional .boa.types.Expression expression = 15; + * + *
+     ** The method body expression, if the body is not composed of statements. 
+     * 
+ */ + boa.types.Ast.Expression getExpression(); + /** + * optional .boa.types.Expression expression = 15; + * + *
+     ** The method body expression, if the body is not composed of statements. 
+     * 
+ */ + boa.types.Ast.ExpressionOrBuilder getExpressionOrBuilder(); + + // optional .boa.types.Type receiver_type = 16; + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+     ** Reciever types 
+     * 
+ */ + boolean hasReceiverType(); + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+     ** Reciever types 
+     * 
+ */ + boa.types.Ast.Type getReceiverType(); + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+     ** Reciever types 
+     * 
+ */ + boa.types.Ast.TypeOrBuilder getReceiverTypeOrBuilder(); } /** * Protobuf type {@code boa.types.Method} @@ -13776,6 +14177,32 @@ private Method( bitField0_ |= 0x00000010; break; } + case 122: { + boa.types.Ast.Expression.Builder subBuilder = null; + if (((bitField0_ & 0x00000020) == 0x00000020)) { + subBuilder = expression_.toBuilder(); + } + expression_ = input.readMessage(boa.types.Ast.Expression.PARSER, extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom(expression_); + expression_ = subBuilder.buildPartial(); + } + bitField0_ |= 0x00000020; + break; + } + case 130: { + boa.types.Ast.Type.Builder subBuilder = null; + if (((bitField0_ & 0x00000040) == 0x00000040)) { + subBuilder = receiverType_.toBuilder(); + } + receiverType_ = input.readMessage(boa.types.Ast.Type.PARSER, extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom(receiverType_); + receiverType_ = subBuilder.buildPartial(); + } + bitField0_ |= 0x00000040; + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -14356,6 +14783,74 @@ public boa.types.Ast.ExpressionOrBuilder getComputedNameOrBuilder() { return computedName_; } + // optional .boa.types.Expression expression = 15; + public static final int EXPRESSION_FIELD_NUMBER = 15; + private boa.types.Ast.Expression expression_; + /** + * optional .boa.types.Expression expression = 15; + * + *
+     ** The method body expression, if the body is not composed of statements. 
+     * 
+ */ + public boolean hasExpression() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + /** + * optional .boa.types.Expression expression = 15; + * + *
+     ** The method body expression, if the body is not composed of statements. 
+     * 
+ */ + public boa.types.Ast.Expression getExpression() { + return expression_; + } + /** + * optional .boa.types.Expression expression = 15; + * + *
+     ** The method body expression, if the body is not composed of statements. 
+     * 
+ */ + public boa.types.Ast.ExpressionOrBuilder getExpressionOrBuilder() { + return expression_; + } + + // optional .boa.types.Type receiver_type = 16; + public static final int RECEIVER_TYPE_FIELD_NUMBER = 16; + private boa.types.Ast.Type receiverType_; + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+     ** Reciever types 
+     * 
+ */ + public boolean hasReceiverType() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+     ** Reciever types 
+     * 
+ */ + public boa.types.Ast.Type getReceiverType() { + return receiverType_; + } + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+     ** Reciever types 
+     * 
+ */ + public boa.types.Ast.TypeOrBuilder getReceiverTypeOrBuilder() { + return receiverType_; + } + private void initFields() { name_ = ""; modifiers_ = java.util.Collections.emptyList(); @@ -14368,6 +14863,8 @@ private void initFields() { key_ = 0; declaringType_ = 0; computedName_ = boa.types.Ast.Expression.getDefaultInstance(); + expression_ = boa.types.Ast.Expression.getDefaultInstance(); + receiverType_ = boa.types.Ast.Type.getDefaultInstance(); } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -14422,6 +14919,18 @@ public final boolean isInitialized() { return false; } } + if (hasExpression()) { + if (!getExpression().isInitialized()) { + memoizedIsInitialized = 0; + return false; + } + } + if (hasReceiverType()) { + if (!getReceiverType().isInitialized()) { + memoizedIsInitialized = 0; + return false; + } + } memoizedIsInitialized = 1; return true; } @@ -14462,6 +14971,12 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (((bitField0_ & 0x00000010) == 0x00000010)) { output.writeMessage(14, computedName_); } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + output.writeMessage(15, expression_); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + output.writeMessage(16, receiverType_); + } getUnknownFields().writeTo(output); } @@ -14515,6 +15030,14 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeMessageSize(14, computedName_); } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(15, expression_); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(16, receiverType_); + } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; @@ -14635,6 +15158,8 @@ private void maybeForceBuilderInitialization() { getStatementsFieldBuilder(); getCommentsFieldBuilder(); getComputedNameFieldBuilder(); + getExpressionFieldBuilder(); + getReceiverTypeFieldBuilder(); } } private static Builder create() { @@ -14697,6 +15222,18 @@ public Builder clear() { computedNameBuilder_.clear(); } bitField0_ = (bitField0_ & ~0x00000400); + if (expressionBuilder_ == null) { + expression_ = boa.types.Ast.Expression.getDefaultInstance(); + } else { + expressionBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000800); + if (receiverTypeBuilder_ == null) { + receiverType_ = boa.types.Ast.Type.getDefaultInstance(); + } else { + receiverTypeBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00001000); return this; } @@ -14807,6 +15344,22 @@ public boa.types.Ast.Method buildPartial() { } else { result.computedName_ = computedNameBuilder_.build(); } + if (((from_bitField0_ & 0x00000800) == 0x00000800)) { + to_bitField0_ |= 0x00000020; + } + if (expressionBuilder_ == null) { + result.expression_ = expression_; + } else { + result.expression_ = expressionBuilder_.build(); + } + if (((from_bitField0_ & 0x00001000) == 0x00001000)) { + to_bitField0_ |= 0x00000040; + } + if (receiverTypeBuilder_ == null) { + result.receiverType_ = receiverType_; + } else { + result.receiverType_ = receiverTypeBuilder_.build(); + } result.bitField0_ = to_bitField0_; onBuilt(); return result; @@ -14996,6 +15549,12 @@ public Builder mergeFrom(boa.types.Ast.Method other) { if (other.hasComputedName()) { mergeComputedName(other.getComputedName()); } + if (other.hasExpression()) { + mergeExpression(other.getExpression()); + } + if (other.hasReceiverType()) { + mergeReceiverType(other.getReceiverType()); + } this.mergeUnknownFields(other.getUnknownFields()); return this; } @@ -15049,6 +15608,18 @@ public final boolean isInitialized() { return false; } } + if (hasExpression()) { + if (!getExpression().isInitialized()) { + + return false; + } + } + if (hasReceiverType()) { + if (!getReceiverType().isInitialized()) { + + return false; + } + } return true; } @@ -17499,6 +18070,312 @@ public boa.types.Ast.ExpressionOrBuilder getComputedNameOrBuilder() { return computedNameBuilder_; } + // optional .boa.types.Expression expression = 15; + private boa.types.Ast.Expression expression_ = boa.types.Ast.Expression.getDefaultInstance(); + private com.google.protobuf.SingleFieldBuilder< + boa.types.Ast.Expression, boa.types.Ast.Expression.Builder, boa.types.Ast.ExpressionOrBuilder> expressionBuilder_; + /** + * optional .boa.types.Expression expression = 15; + * + *
+       ** The method body expression, if the body is not composed of statements. 
+       * 
+ */ + public boolean hasExpression() { + return ((bitField0_ & 0x00000800) == 0x00000800); + } + /** + * optional .boa.types.Expression expression = 15; + * + *
+       ** The method body expression, if the body is not composed of statements. 
+       * 
+ */ + public boa.types.Ast.Expression getExpression() { + if (expressionBuilder_ == null) { + return expression_; + } else { + return expressionBuilder_.getMessage(); + } + } + /** + * optional .boa.types.Expression expression = 15; + * + *
+       ** The method body expression, if the body is not composed of statements. 
+       * 
+ */ + public Builder setExpression(boa.types.Ast.Expression value) { + if (expressionBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + expression_ = value; + onChanged(); + } else { + expressionBuilder_.setMessage(value); + } + bitField0_ |= 0x00000800; + return this; + } + /** + * optional .boa.types.Expression expression = 15; + * + *
+       ** The method body expression, if the body is not composed of statements. 
+       * 
+ */ + public Builder setExpression( + boa.types.Ast.Expression.Builder builderForValue) { + if (expressionBuilder_ == null) { + expression_ = builderForValue.build(); + onChanged(); + } else { + expressionBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000800; + return this; + } + /** + * optional .boa.types.Expression expression = 15; + * + *
+       ** The method body expression, if the body is not composed of statements. 
+       * 
+ */ + public Builder mergeExpression(boa.types.Ast.Expression value) { + if (expressionBuilder_ == null) { + if (((bitField0_ & 0x00000800) == 0x00000800) && + expression_ != boa.types.Ast.Expression.getDefaultInstance()) { + expression_ = + boa.types.Ast.Expression.newBuilder(expression_).mergeFrom(value).buildPartial(); + } else { + expression_ = value; + } + onChanged(); + } else { + expressionBuilder_.mergeFrom(value); + } + bitField0_ |= 0x00000800; + return this; + } + /** + * optional .boa.types.Expression expression = 15; + * + *
+       ** The method body expression, if the body is not composed of statements. 
+       * 
+ */ + public Builder clearExpression() { + if (expressionBuilder_ == null) { + expression_ = boa.types.Ast.Expression.getDefaultInstance(); + onChanged(); + } else { + expressionBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000800); + return this; + } + /** + * optional .boa.types.Expression expression = 15; + * + *
+       ** The method body expression, if the body is not composed of statements. 
+       * 
+ */ + public boa.types.Ast.Expression.Builder getExpressionBuilder() { + bitField0_ |= 0x00000800; + onChanged(); + return getExpressionFieldBuilder().getBuilder(); + } + /** + * optional .boa.types.Expression expression = 15; + * + *
+       ** The method body expression, if the body is not composed of statements. 
+       * 
+ */ + public boa.types.Ast.ExpressionOrBuilder getExpressionOrBuilder() { + if (expressionBuilder_ != null) { + return expressionBuilder_.getMessageOrBuilder(); + } else { + return expression_; + } + } + /** + * optional .boa.types.Expression expression = 15; + * + *
+       ** The method body expression, if the body is not composed of statements. 
+       * 
+ */ + private com.google.protobuf.SingleFieldBuilder< + boa.types.Ast.Expression, boa.types.Ast.Expression.Builder, boa.types.Ast.ExpressionOrBuilder> + getExpressionFieldBuilder() { + if (expressionBuilder_ == null) { + expressionBuilder_ = new com.google.protobuf.SingleFieldBuilder< + boa.types.Ast.Expression, boa.types.Ast.Expression.Builder, boa.types.Ast.ExpressionOrBuilder>( + expression_, + getParentForChildren(), + isClean()); + expression_ = null; + } + return expressionBuilder_; + } + + // optional .boa.types.Type receiver_type = 16; + private boa.types.Ast.Type receiverType_ = boa.types.Ast.Type.getDefaultInstance(); + private com.google.protobuf.SingleFieldBuilder< + boa.types.Ast.Type, boa.types.Ast.Type.Builder, boa.types.Ast.TypeOrBuilder> receiverTypeBuilder_; + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+       ** Reciever types 
+       * 
+ */ + public boolean hasReceiverType() { + return ((bitField0_ & 0x00001000) == 0x00001000); + } + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+       ** Reciever types 
+       * 
+ */ + public boa.types.Ast.Type getReceiverType() { + if (receiverTypeBuilder_ == null) { + return receiverType_; + } else { + return receiverTypeBuilder_.getMessage(); + } + } + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+       ** Reciever types 
+       * 
+ */ + public Builder setReceiverType(boa.types.Ast.Type value) { + if (receiverTypeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + receiverType_ = value; + onChanged(); + } else { + receiverTypeBuilder_.setMessage(value); + } + bitField0_ |= 0x00001000; + return this; + } + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+       ** Reciever types 
+       * 
+ */ + public Builder setReceiverType( + boa.types.Ast.Type.Builder builderForValue) { + if (receiverTypeBuilder_ == null) { + receiverType_ = builderForValue.build(); + onChanged(); + } else { + receiverTypeBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00001000; + return this; + } + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+       ** Reciever types 
+       * 
+ */ + public Builder mergeReceiverType(boa.types.Ast.Type value) { + if (receiverTypeBuilder_ == null) { + if (((bitField0_ & 0x00001000) == 0x00001000) && + receiverType_ != boa.types.Ast.Type.getDefaultInstance()) { + receiverType_ = + boa.types.Ast.Type.newBuilder(receiverType_).mergeFrom(value).buildPartial(); + } else { + receiverType_ = value; + } + onChanged(); + } else { + receiverTypeBuilder_.mergeFrom(value); + } + bitField0_ |= 0x00001000; + return this; + } + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+       ** Reciever types 
+       * 
+ */ + public Builder clearReceiverType() { + if (receiverTypeBuilder_ == null) { + receiverType_ = boa.types.Ast.Type.getDefaultInstance(); + onChanged(); + } else { + receiverTypeBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00001000); + return this; + } + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+       ** Reciever types 
+       * 
+ */ + public boa.types.Ast.Type.Builder getReceiverTypeBuilder() { + bitField0_ |= 0x00001000; + onChanged(); + return getReceiverTypeFieldBuilder().getBuilder(); + } + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+       ** Reciever types 
+       * 
+ */ + public boa.types.Ast.TypeOrBuilder getReceiverTypeOrBuilder() { + if (receiverTypeBuilder_ != null) { + return receiverTypeBuilder_.getMessageOrBuilder(); + } else { + return receiverType_; + } + } + /** + * optional .boa.types.Type receiver_type = 16; + * + *
+       ** Reciever types 
+       * 
+ */ + private com.google.protobuf.SingleFieldBuilder< + boa.types.Ast.Type, boa.types.Ast.Type.Builder, boa.types.Ast.TypeOrBuilder> + getReceiverTypeFieldBuilder() { + if (receiverTypeBuilder_ == null) { + receiverTypeBuilder_ = new com.google.protobuf.SingleFieldBuilder< + boa.types.Ast.Type, boa.types.Ast.Type.Builder, boa.types.Ast.TypeOrBuilder>( + receiverType_, + getParentForChildren(), + isClean()); + receiverType_ = null; + } + return receiverTypeBuilder_; + } + // @@protoc_insertion_point(builder_scope:boa.types.Method) } @@ -25784,31 +26661,50 @@ boa.types.Ast.ExpressionOrBuilder getMethodArgsOrBuilder( */ boa.types.Ast.DeclarationOrBuilder getAnonDeclarationOrBuilder(); - // optional .boa.types.Modifier annotation = 12; + // repeated .boa.types.Modifier modifiers = 12; /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
      ** 13 used to be lambda 
      * 
*/ - boolean hasAnnotation(); + java.util.List + getModifiersList(); /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
      ** 13 used to be lambda 
      * 
*/ - boa.types.Ast.Modifier getAnnotation(); + boa.types.Ast.Modifier getModifiers(int index); /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
      ** 13 used to be lambda 
      * 
*/ - boa.types.Ast.ModifierOrBuilder getAnnotationOrBuilder(); + int getModifiersCount(); + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+     ** 13 used to be lambda 
+     * 
+ */ + java.util.List + getModifiersOrBuilderList(); + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+     ** 13 used to be lambda 
+     * 
+ */ + boa.types.Ast.ModifierOrBuilder getModifiersOrBuilder( + int index); // optional bool no_parens = 14; /** @@ -26069,6 +26965,16 @@ boa.types.Ast.StatementOrBuilder getStatementsOrBuilder( * optional .boa.types.Method trait = 29; */ boa.types.Ast.MethodOrBuilder getTraitOrBuilder(); + + // optional bool safe = 30; + /** + * optional bool safe = 30; + */ + boolean hasSafe(); + /** + * optional bool safe = 30; + */ + boolean getSafe(); } /** * Protobuf type {@code boa.types.Expression} @@ -26215,31 +27121,26 @@ private Expression( break; } case 98: { - boa.types.Ast.Modifier.Builder subBuilder = null; - if (((bitField0_ & 0x00000080) == 0x00000080)) { - subBuilder = annotation_.toBuilder(); - } - annotation_ = input.readMessage(boa.types.Ast.Modifier.PARSER, extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(annotation_); - annotation_ = subBuilder.buildPartial(); + if (!((mutable_bitField0_ & 0x00000800) == 0x00000800)) { + modifiers_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000800; } - bitField0_ |= 0x00000080; + modifiers_.add(input.readMessage(boa.types.Ast.Modifier.PARSER, extensionRegistry)); break; } case 112: { - bitField0_ |= 0x00000100; + bitField0_ |= 0x00000080; noParens_ = input.readBool(); break; } case 144: { - bitField0_ |= 0x00000200; + bitField0_ |= 0x00000100; key_ = input.readInt32(); break; } case 154: { boa.types.Ast.Type.Builder subBuilder = null; - if (((bitField0_ & 0x00000400) == 0x00000400)) { + if (((bitField0_ & 0x00000200) == 0x00000200)) { subBuilder = declaringType_.toBuilder(); } declaringType_ = input.readMessage(boa.types.Ast.Type.PARSER, extensionRegistry); @@ -26247,12 +27148,12 @@ private Expression( subBuilder.mergeFrom(declaringType_); declaringType_ = subBuilder.buildPartial(); } - bitField0_ |= 0x00000400; + bitField0_ |= 0x00000200; break; } case 162: { boa.types.Ast.Type.Builder subBuilder = null; - if (((bitField0_ & 0x00000800) == 0x00000800)) { + if (((bitField0_ & 0x00000400) == 0x00000400)) { subBuilder = returnType_.toBuilder(); } returnType_ = input.readMessage(boa.types.Ast.Type.PARSER, extensionRegistry); @@ -26260,7 +27161,7 @@ private Expression( subBuilder.mergeFrom(returnType_); returnType_ = subBuilder.buildPartial(); } - bitField0_ |= 0x00000800; + bitField0_ |= 0x00000400; break; } case 170: { @@ -26280,18 +27181,18 @@ private Expression( break; } case 184: { - bitField0_ |= 0x00001000; + bitField0_ |= 0x00000800; isMemberAccess_ = input.readBool(); break; } case 192: { - bitField0_ |= 0x00002000; + bitField0_ |= 0x00001000; dollarSign_ = input.readBool(); break; } case 202: { boa.types.Ast.Expression.Builder subBuilder = null; - if (((bitField0_ & 0x00004000) == 0x00004000)) { + if (((bitField0_ & 0x00002000) == 0x00002000)) { subBuilder = computedVariable_.toBuilder(); } computedVariable_ = input.readMessage(boa.types.Ast.Expression.PARSER, extensionRegistry); @@ -26299,12 +27200,12 @@ private Expression( subBuilder.mergeFrom(computedVariable_); computedVariable_ = subBuilder.buildPartial(); } - bitField0_ |= 0x00004000; + bitField0_ |= 0x00002000; break; } case 210: { boa.types.Ast.Expression.Builder subBuilder = null; - if (((bitField0_ & 0x00008000) == 0x00008000)) { + if (((bitField0_ & 0x00004000) == 0x00004000)) { subBuilder = computedMethod_.toBuilder(); } computedMethod_ = input.readMessage(boa.types.Ast.Expression.PARSER, extensionRegistry); @@ -26312,22 +27213,22 @@ private Expression( subBuilder.mergeFrom(computedMethod_); computedMethod_ = subBuilder.buildPartial(); } - bitField0_ |= 0x00008000; + bitField0_ |= 0x00004000; break; } case 216: { - bitField0_ |= 0x00010000; + bitField0_ |= 0x00008000; isStatic_ = input.readBool(); break; } case 224: { - bitField0_ |= 0x00020000; + bitField0_ |= 0x00010000; hasFrom_ = input.readBool(); break; } case 234: { boa.types.Ast.Method.Builder subBuilder = null; - if (((bitField0_ & 0x00040000) == 0x00040000)) { + if (((bitField0_ & 0x00020000) == 0x00020000)) { subBuilder = trait_.toBuilder(); } trait_ = input.readMessage(boa.types.Ast.Method.PARSER, extensionRegistry); @@ -26335,7 +27236,12 @@ private Expression( subBuilder.mergeFrom(trait_); trait_ = subBuilder.buildPartial(); } + bitField0_ |= 0x00020000; + break; + } + case 240: { bitField0_ |= 0x00040000; + safe_ = input.readBool(); break; } } @@ -26358,6 +27264,9 @@ private Expression( if (((mutable_bitField0_ & 0x00000200) == 0x00000200)) { methodArgs_ = java.util.Collections.unmodifiableList(methodArgs_); } + if (((mutable_bitField0_ & 0x00000800) == 0x00000800)) { + modifiers_ = java.util.Collections.unmodifiableList(modifiers_); + } if (((mutable_bitField0_ & 0x00010000) == 0x00010000)) { methods_ = java.util.Collections.unmodifiableList(methods_); } @@ -26832,6 +27741,30 @@ public enum ExpressionKind * NAMESPACENAME = 100; */ NAMESPACENAME(101, 100), + /** + * STATEMENT = 101; + */ + STATEMENT(102, 101), + /** + * TEMPLATE = 102; + */ + TEMPLATE(103, 102), + /** + * LABEL = 103; + */ + LABEL(104, 103), + /** + * OP_ELVIS = 104; + */ + OP_ELVIS(105, 104), + /** + * NOT_IN = 105; + */ + NOT_IN(106, 105), + /** + * OP_NOTNULL = 106; + */ + OP_NOTNULL(107, 106), ; /** @@ -27278,6 +28211,30 @@ public enum ExpressionKind * NAMESPACENAME = 100; */ public static final int NAMESPACENAME_VALUE = 100; + /** + * STATEMENT = 101; + */ + public static final int STATEMENT_VALUE = 101; + /** + * TEMPLATE = 102; + */ + public static final int TEMPLATE_VALUE = 102; + /** + * LABEL = 103; + */ + public static final int LABEL_VALUE = 103; + /** + * OP_ELVIS = 104; + */ + public static final int OP_ELVIS_VALUE = 104; + /** + * NOT_IN = 105; + */ + public static final int NOT_IN_VALUE = 105; + /** + * OP_NOTNULL = 106; + */ + public static final int OP_NOTNULL_VALUE = 106; public final int getNumber() { return value; } @@ -27385,6 +28342,12 @@ public static ExpressionKind valueOf(int value) { case 98: return TRAIT_ALIAS; case 99: return TRAIT_PRECEDENCE; case 100: return NAMESPACENAME; + case 101: return STATEMENT; + case 102: return TEMPLATE; + case 103: return LABEL; + case 104: return OP_ELVIS; + case 105: return NOT_IN; + case 106: return OP_NOTNULL; default: return null; } } @@ -27415,7 +28378,7 @@ public ExpressionKind findValueByNumber(int number) { } private static final ExpressionKind[] VALUES = { - OTHER, LITERAL, VARACCESS, VARDECL, METHODCALL, CAST, ARRAYACCESS, ARRAYINIT, ARRAYLITERAL, TYPECOMPARE, NEW, NEWARRAY, OP_ADD, OP_SUB, OP_MULT, OP_DIV, OP_MOD, OP_INC, OP_DEC, BIT_LSHIFT, BIT_RSHIFT, BIT_UNSIGNEDRSHIFT, BIT_AND, BIT_OR, BIT_NOT, BIT_XOR, LOGICAL_NOT, LOGICAL_AND, LOGICAL_OR, EQ, NEQ, LT, GT, LTEQ, GTEQ, CONDITIONAL, NULLCOALESCE, ASSIGN, ASSIGN_ADD, ASSIGN_SUB, ASSIGN_MULT, ASSIGN_DIV, ASSIGN_MOD, ASSIGN_BITXOR, ASSIGN_BITAND, ASSIGN_BITOR, ASSIGN_LSHIFT, ASSIGN_RSHIFT, ASSIGN_UNSIGNEDRSHIFT, ANNOTATION, PAREN, METHOD_REFERENCE, LAMBDA, ANON_METHOD, YIELD, ARRAY_COMPREHENSION, EMPTY, SHEQ, SHNEQ, XML_DOTQUERY, OBJECT_LITERAL, METHODDECL, LOOP, GENERATOR, XML_LITERAL, XML_EXPRESSION, XML_PROPERTYREF, XML_MEMBERREF, XML_DOT, XML_DOTDOT, IN, TYPEOF, REGEXPLITERAL, DELETE, VOID, HASHTABLEACCESS, ARRAYELEMENT, OP_CONCAT, OP_POW, ASSIGN_CONCAT, ASSIGN_POW, BACKTICK, IDENTICAL, NOTIDENTICAL, STRING_AND, STRING_OR, STRING_XOR, OP_THREE_WAY_COMPARE, OP_UNPACK, QUOTE, IGNORE_ERROR, REQUIRE, REQUIRE_ONCE, INCLUDE, INCLUDE_ONCE, LIST, REFERENCE, REFLECTION, CLONE, TRAIT_ALIAS, TRAIT_PRECEDENCE, NAMESPACENAME, + OTHER, LITERAL, VARACCESS, VARDECL, METHODCALL, CAST, ARRAYACCESS, ARRAYINIT, ARRAYLITERAL, TYPECOMPARE, NEW, NEWARRAY, OP_ADD, OP_SUB, OP_MULT, OP_DIV, OP_MOD, OP_INC, OP_DEC, BIT_LSHIFT, BIT_RSHIFT, BIT_UNSIGNEDRSHIFT, BIT_AND, BIT_OR, BIT_NOT, BIT_XOR, LOGICAL_NOT, LOGICAL_AND, LOGICAL_OR, EQ, NEQ, LT, GT, LTEQ, GTEQ, CONDITIONAL, NULLCOALESCE, ASSIGN, ASSIGN_ADD, ASSIGN_SUB, ASSIGN_MULT, ASSIGN_DIV, ASSIGN_MOD, ASSIGN_BITXOR, ASSIGN_BITAND, ASSIGN_BITOR, ASSIGN_LSHIFT, ASSIGN_RSHIFT, ASSIGN_UNSIGNEDRSHIFT, ANNOTATION, PAREN, METHOD_REFERENCE, LAMBDA, ANON_METHOD, YIELD, ARRAY_COMPREHENSION, EMPTY, SHEQ, SHNEQ, XML_DOTQUERY, OBJECT_LITERAL, METHODDECL, LOOP, GENERATOR, XML_LITERAL, XML_EXPRESSION, XML_PROPERTYREF, XML_MEMBERREF, XML_DOT, XML_DOTDOT, IN, TYPEOF, REGEXPLITERAL, DELETE, VOID, HASHTABLEACCESS, ARRAYELEMENT, OP_CONCAT, OP_POW, ASSIGN_CONCAT, ASSIGN_POW, BACKTICK, IDENTICAL, NOTIDENTICAL, STRING_AND, STRING_OR, STRING_XOR, OP_THREE_WAY_COMPARE, OP_UNPACK, QUOTE, IGNORE_ERROR, REQUIRE, REQUIRE_ONCE, INCLUDE, INCLUDE_ONCE, LIST, REFERENCE, REFLECTION, CLONE, TRAIT_ALIAS, TRAIT_PRECEDENCE, NAMESPACENAME, STATEMENT, TEMPLATE, LABEL, OP_ELVIS, NOT_IN, OP_NOTNULL, }; public static ExpressionKind valueOf( @@ -27796,38 +28759,60 @@ public boa.types.Ast.DeclarationOrBuilder getAnonDeclarationOrBuilder() { return anonDeclaration_; } - // optional .boa.types.Modifier annotation = 12; - public static final int ANNOTATION_FIELD_NUMBER = 12; - private boa.types.Ast.Modifier annotation_; + // repeated .boa.types.Modifier modifiers = 12; + public static final int MODIFIERS_FIELD_NUMBER = 12; + private java.util.List modifiers_; /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
      ** 13 used to be lambda 
      * 
*/ - public boolean hasAnnotation() { - return ((bitField0_ & 0x00000080) == 0x00000080); + public java.util.List getModifiersList() { + return modifiers_; } /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
      ** 13 used to be lambda 
      * 
*/ - public boa.types.Ast.Modifier getAnnotation() { - return annotation_; + public java.util.List + getModifiersOrBuilderList() { + return modifiers_; } /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
      ** 13 used to be lambda 
      * 
*/ - public boa.types.Ast.ModifierOrBuilder getAnnotationOrBuilder() { - return annotation_; + public int getModifiersCount() { + return modifiers_.size(); + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+     ** 13 used to be lambda 
+     * 
+ */ + public boa.types.Ast.Modifier getModifiers(int index) { + return modifiers_.get(index); + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+     ** 13 used to be lambda 
+     * 
+ */ + public boa.types.Ast.ModifierOrBuilder getModifiersOrBuilder( + int index) { + return modifiers_.get(index); } // optional bool no_parens = 14; @@ -27841,7 +28826,7 @@ public boa.types.Ast.ModifierOrBuilder getAnnotationOrBuilder() { * */ public boolean hasNoParens() { - return ((bitField0_ & 0x00000100) == 0x00000100); + return ((bitField0_ & 0x00000080) == 0x00000080); } /** * optional bool no_parens = 14; @@ -27865,7 +28850,7 @@ public boolean getNoParens() { * */ public boolean hasKey() { - return ((bitField0_ & 0x00000200) == 0x00000200); + return ((bitField0_ & 0x00000100) == 0x00000100); } /** * optional int32 key = 18; @@ -27889,7 +28874,7 @@ public int getKey() { * */ public boolean hasDeclaringType() { - return ((bitField0_ & 0x00000400) == 0x00000400); + return ((bitField0_ & 0x00000200) == 0x00000200); } /** * optional .boa.types.Type declaring_type = 19; @@ -27923,7 +28908,7 @@ public boa.types.Ast.TypeOrBuilder getDeclaringTypeOrBuilder() { * */ public boolean hasReturnType() { - return ((bitField0_ & 0x00000800) == 0x00000800); + return ((bitField0_ & 0x00000400) == 0x00000400); } /** * optional .boa.types.Type return_type = 20; @@ -28065,7 +29050,7 @@ public boa.types.Ast.StatementOrBuilder getStatementsOrBuilder( * optional bool is_member_access = 23; */ public boolean hasIsMemberAccess() { - return ((bitField0_ & 0x00001000) == 0x00001000); + return ((bitField0_ & 0x00000800) == 0x00000800); } /** * optional bool is_member_access = 23; @@ -28081,7 +29066,7 @@ public boolean getIsMemberAccess() { * optional bool dollar_sign = 24; */ public boolean hasDollarSign() { - return ((bitField0_ & 0x00002000) == 0x00002000); + return ((bitField0_ & 0x00001000) == 0x00001000); } /** * optional bool dollar_sign = 24; @@ -28097,7 +29082,7 @@ public boolean getDollarSign() { * optional .boa.types.Expression computed_variable = 25; */ public boolean hasComputedVariable() { - return ((bitField0_ & 0x00004000) == 0x00004000); + return ((bitField0_ & 0x00002000) == 0x00002000); } /** * optional .boa.types.Expression computed_variable = 25; @@ -28119,7 +29104,7 @@ public boa.types.Ast.ExpressionOrBuilder getComputedVariableOrBuilder() { * optional .boa.types.Expression computed_method = 26; */ public boolean hasComputedMethod() { - return ((bitField0_ & 0x00008000) == 0x00008000); + return ((bitField0_ & 0x00004000) == 0x00004000); } /** * optional .boa.types.Expression computed_method = 26; @@ -28141,7 +29126,7 @@ public boa.types.Ast.ExpressionOrBuilder getComputedMethodOrBuilder() { * optional bool is_static = 27; */ public boolean hasIsStatic() { - return ((bitField0_ & 0x00010000) == 0x00010000); + return ((bitField0_ & 0x00008000) == 0x00008000); } /** * optional bool is_static = 27; @@ -28157,7 +29142,7 @@ public boolean getIsStatic() { * optional bool has_from = 28; */ public boolean hasHasFrom() { - return ((bitField0_ & 0x00020000) == 0x00020000); + return ((bitField0_ & 0x00010000) == 0x00010000); } /** * optional bool has_from = 28; @@ -28173,7 +29158,7 @@ public boolean getHasFrom() { * optional .boa.types.Method trait = 29; */ public boolean hasTrait() { - return ((bitField0_ & 0x00040000) == 0x00040000); + return ((bitField0_ & 0x00020000) == 0x00020000); } /** * optional .boa.types.Method trait = 29; @@ -28188,6 +29173,22 @@ public boa.types.Ast.MethodOrBuilder getTraitOrBuilder() { return trait_; } + // optional bool safe = 30; + public static final int SAFE_FIELD_NUMBER = 30; + private boolean safe_; + /** + * optional bool safe = 30; + */ + public boolean hasSafe() { + return ((bitField0_ & 0x00040000) == 0x00040000); + } + /** + * optional bool safe = 30; + */ + public boolean getSafe() { + return safe_; + } + private void initFields() { kind_ = boa.types.Ast.Expression.ExpressionKind.OTHER; expressions_ = java.util.Collections.emptyList(); @@ -28200,7 +29201,7 @@ private void initFields() { method_ = ""; methodArgs_ = java.util.Collections.emptyList(); anonDeclaration_ = boa.types.Ast.Declaration.getDefaultInstance(); - annotation_ = boa.types.Ast.Modifier.getDefaultInstance(); + modifiers_ = java.util.Collections.emptyList(); noParens_ = false; key_ = 0; declaringType_ = boa.types.Ast.Type.getDefaultInstance(); @@ -28214,6 +29215,7 @@ private void initFields() { isStatic_ = false; hasFrom_ = false; trait_ = boa.types.Ast.Method.getDefaultInstance(); + safe_ = false; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -28260,8 +29262,8 @@ public final boolean isInitialized() { return false; } } - if (hasAnnotation()) { - if (!getAnnotation().isInitialized()) { + for (int i = 0; i < getModifiersCount(); i++) { + if (!getModifiers(i).isInitialized()) { memoizedIsInitialized = 0; return false; } @@ -28348,19 +29350,19 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (((bitField0_ & 0x00000040) == 0x00000040)) { output.writeMessage(11, anonDeclaration_); } - if (((bitField0_ & 0x00000080) == 0x00000080)) { - output.writeMessage(12, annotation_); + for (int i = 0; i < modifiers_.size(); i++) { + output.writeMessage(12, modifiers_.get(i)); } - if (((bitField0_ & 0x00000100) == 0x00000100)) { + if (((bitField0_ & 0x00000080) == 0x00000080)) { output.writeBool(14, noParens_); } - if (((bitField0_ & 0x00000200) == 0x00000200)) { + if (((bitField0_ & 0x00000100) == 0x00000100)) { output.writeInt32(18, key_); } - if (((bitField0_ & 0x00000400) == 0x00000400)) { + if (((bitField0_ & 0x00000200) == 0x00000200)) { output.writeMessage(19, declaringType_); } - if (((bitField0_ & 0x00000800) == 0x00000800)) { + if (((bitField0_ & 0x00000400) == 0x00000400)) { output.writeMessage(20, returnType_); } for (int i = 0; i < methods_.size(); i++) { @@ -28369,27 +29371,30 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) for (int i = 0; i < statements_.size(); i++) { output.writeMessage(22, statements_.get(i)); } - if (((bitField0_ & 0x00001000) == 0x00001000)) { + if (((bitField0_ & 0x00000800) == 0x00000800)) { output.writeBool(23, isMemberAccess_); } - if (((bitField0_ & 0x00002000) == 0x00002000)) { + if (((bitField0_ & 0x00001000) == 0x00001000)) { output.writeBool(24, dollarSign_); } - if (((bitField0_ & 0x00004000) == 0x00004000)) { + if (((bitField0_ & 0x00002000) == 0x00002000)) { output.writeMessage(25, computedVariable_); } - if (((bitField0_ & 0x00008000) == 0x00008000)) { + if (((bitField0_ & 0x00004000) == 0x00004000)) { output.writeMessage(26, computedMethod_); } - if (((bitField0_ & 0x00010000) == 0x00010000)) { + if (((bitField0_ & 0x00008000) == 0x00008000)) { output.writeBool(27, isStatic_); } - if (((bitField0_ & 0x00020000) == 0x00020000)) { + if (((bitField0_ & 0x00010000) == 0x00010000)) { output.writeBool(28, hasFrom_); } - if (((bitField0_ & 0x00040000) == 0x00040000)) { + if (((bitField0_ & 0x00020000) == 0x00020000)) { output.writeMessage(29, trait_); } + if (((bitField0_ & 0x00040000) == 0x00040000)) { + output.writeBool(30, safe_); + } getUnknownFields().writeTo(output); } @@ -28443,23 +29448,23 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeMessageSize(11, anonDeclaration_); } - if (((bitField0_ & 0x00000080) == 0x00000080)) { + for (int i = 0; i < modifiers_.size(); i++) { size += com.google.protobuf.CodedOutputStream - .computeMessageSize(12, annotation_); + .computeMessageSize(12, modifiers_.get(i)); } - if (((bitField0_ & 0x00000100) == 0x00000100)) { + if (((bitField0_ & 0x00000080) == 0x00000080)) { size += com.google.protobuf.CodedOutputStream .computeBoolSize(14, noParens_); } - if (((bitField0_ & 0x00000200) == 0x00000200)) { + if (((bitField0_ & 0x00000100) == 0x00000100)) { size += com.google.protobuf.CodedOutputStream .computeInt32Size(18, key_); } - if (((bitField0_ & 0x00000400) == 0x00000400)) { + if (((bitField0_ & 0x00000200) == 0x00000200)) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(19, declaringType_); } - if (((bitField0_ & 0x00000800) == 0x00000800)) { + if (((bitField0_ & 0x00000400) == 0x00000400)) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(20, returnType_); } @@ -28471,34 +29476,38 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeMessageSize(22, statements_.get(i)); } - if (((bitField0_ & 0x00001000) == 0x00001000)) { + if (((bitField0_ & 0x00000800) == 0x00000800)) { size += com.google.protobuf.CodedOutputStream .computeBoolSize(23, isMemberAccess_); } - if (((bitField0_ & 0x00002000) == 0x00002000)) { + if (((bitField0_ & 0x00001000) == 0x00001000)) { size += com.google.protobuf.CodedOutputStream .computeBoolSize(24, dollarSign_); } - if (((bitField0_ & 0x00004000) == 0x00004000)) { + if (((bitField0_ & 0x00002000) == 0x00002000)) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(25, computedVariable_); } - if (((bitField0_ & 0x00008000) == 0x00008000)) { + if (((bitField0_ & 0x00004000) == 0x00004000)) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(26, computedMethod_); } - if (((bitField0_ & 0x00010000) == 0x00010000)) { + if (((bitField0_ & 0x00008000) == 0x00008000)) { size += com.google.protobuf.CodedOutputStream .computeBoolSize(27, isStatic_); } - if (((bitField0_ & 0x00020000) == 0x00020000)) { + if (((bitField0_ & 0x00010000) == 0x00010000)) { size += com.google.protobuf.CodedOutputStream .computeBoolSize(28, hasFrom_); } - if (((bitField0_ & 0x00040000) == 0x00040000)) { + if (((bitField0_ & 0x00020000) == 0x00020000)) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(29, trait_); } + if (((bitField0_ & 0x00040000) == 0x00040000)) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(30, safe_); + } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; @@ -28617,7 +29626,7 @@ private void maybeForceBuilderInitialization() { getGenericParametersFieldBuilder(); getMethodArgsFieldBuilder(); getAnonDeclarationFieldBuilder(); - getAnnotationFieldBuilder(); + getModifiersFieldBuilder(); getDeclaringTypeFieldBuilder(); getReturnTypeFieldBuilder(); getMethodsFieldBuilder(); @@ -28679,12 +29688,12 @@ public Builder clear() { anonDeclarationBuilder_.clear(); } bitField0_ = (bitField0_ & ~0x00000400); - if (annotationBuilder_ == null) { - annotation_ = boa.types.Ast.Modifier.getDefaultInstance(); + if (modifiersBuilder_ == null) { + modifiers_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000800); } else { - annotationBuilder_.clear(); + modifiersBuilder_.clear(); } - bitField0_ = (bitField0_ & ~0x00000800); noParens_ = false; bitField0_ = (bitField0_ & ~0x00001000); key_ = 0; @@ -28739,6 +29748,8 @@ public Builder clear() { traitBuilder_.clear(); } bitField0_ = (bitField0_ & ~0x01000000); + safe_ = false; + bitField0_ = (bitField0_ & ~0x02000000); return this; } @@ -28839,24 +29850,25 @@ public boa.types.Ast.Expression buildPartial() { } else { result.anonDeclaration_ = anonDeclarationBuilder_.build(); } - if (((from_bitField0_ & 0x00000800) == 0x00000800)) { - to_bitField0_ |= 0x00000080; - } - if (annotationBuilder_ == null) { - result.annotation_ = annotation_; + if (modifiersBuilder_ == null) { + if (((bitField0_ & 0x00000800) == 0x00000800)) { + modifiers_ = java.util.Collections.unmodifiableList(modifiers_); + bitField0_ = (bitField0_ & ~0x00000800); + } + result.modifiers_ = modifiers_; } else { - result.annotation_ = annotationBuilder_.build(); + result.modifiers_ = modifiersBuilder_.build(); } if (((from_bitField0_ & 0x00001000) == 0x00001000)) { - to_bitField0_ |= 0x00000100; + to_bitField0_ |= 0x00000080; } result.noParens_ = noParens_; if (((from_bitField0_ & 0x00002000) == 0x00002000)) { - to_bitField0_ |= 0x00000200; + to_bitField0_ |= 0x00000100; } result.key_ = key_; if (((from_bitField0_ & 0x00004000) == 0x00004000)) { - to_bitField0_ |= 0x00000400; + to_bitField0_ |= 0x00000200; } if (declaringTypeBuilder_ == null) { result.declaringType_ = declaringType_; @@ -28864,7 +29876,7 @@ public boa.types.Ast.Expression buildPartial() { result.declaringType_ = declaringTypeBuilder_.build(); } if (((from_bitField0_ & 0x00008000) == 0x00008000)) { - to_bitField0_ |= 0x00000800; + to_bitField0_ |= 0x00000400; } if (returnTypeBuilder_ == null) { result.returnType_ = returnType_; @@ -28890,15 +29902,15 @@ public boa.types.Ast.Expression buildPartial() { result.statements_ = statementsBuilder_.build(); } if (((from_bitField0_ & 0x00040000) == 0x00040000)) { - to_bitField0_ |= 0x00001000; + to_bitField0_ |= 0x00000800; } result.isMemberAccess_ = isMemberAccess_; if (((from_bitField0_ & 0x00080000) == 0x00080000)) { - to_bitField0_ |= 0x00002000; + to_bitField0_ |= 0x00001000; } result.dollarSign_ = dollarSign_; if (((from_bitField0_ & 0x00100000) == 0x00100000)) { - to_bitField0_ |= 0x00004000; + to_bitField0_ |= 0x00002000; } if (computedVariableBuilder_ == null) { result.computedVariable_ = computedVariable_; @@ -28906,7 +29918,7 @@ public boa.types.Ast.Expression buildPartial() { result.computedVariable_ = computedVariableBuilder_.build(); } if (((from_bitField0_ & 0x00200000) == 0x00200000)) { - to_bitField0_ |= 0x00008000; + to_bitField0_ |= 0x00004000; } if (computedMethodBuilder_ == null) { result.computedMethod_ = computedMethod_; @@ -28914,21 +29926,25 @@ public boa.types.Ast.Expression buildPartial() { result.computedMethod_ = computedMethodBuilder_.build(); } if (((from_bitField0_ & 0x00400000) == 0x00400000)) { - to_bitField0_ |= 0x00010000; + to_bitField0_ |= 0x00008000; } result.isStatic_ = isStatic_; if (((from_bitField0_ & 0x00800000) == 0x00800000)) { - to_bitField0_ |= 0x00020000; + to_bitField0_ |= 0x00010000; } result.hasFrom_ = hasFrom_; if (((from_bitField0_ & 0x01000000) == 0x01000000)) { - to_bitField0_ |= 0x00040000; + to_bitField0_ |= 0x00020000; } if (traitBuilder_ == null) { result.trait_ = trait_; } else { result.trait_ = traitBuilder_.build(); } + if (((from_bitField0_ & 0x02000000) == 0x02000000)) { + to_bitField0_ |= 0x00040000; + } + result.safe_ = safe_; result.bitField0_ = to_bitField0_; onBuilt(); return result; @@ -29076,8 +30092,31 @@ public Builder mergeFrom(boa.types.Ast.Expression other) { if (other.hasAnonDeclaration()) { mergeAnonDeclaration(other.getAnonDeclaration()); } - if (other.hasAnnotation()) { - mergeAnnotation(other.getAnnotation()); + if (modifiersBuilder_ == null) { + if (!other.modifiers_.isEmpty()) { + if (modifiers_.isEmpty()) { + modifiers_ = other.modifiers_; + bitField0_ = (bitField0_ & ~0x00000800); + } else { + ensureModifiersIsMutable(); + modifiers_.addAll(other.modifiers_); + } + onChanged(); + } + } else { + if (!other.modifiers_.isEmpty()) { + if (modifiersBuilder_.isEmpty()) { + modifiersBuilder_.dispose(); + modifiersBuilder_ = null; + modifiers_ = other.modifiers_; + bitField0_ = (bitField0_ & ~0x00000800); + modifiersBuilder_ = + com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? + getModifiersFieldBuilder() : null; + } else { + modifiersBuilder_.addAllMessages(other.modifiers_); + } + } } if (other.hasNoParens()) { setNoParens(other.getNoParens()); @@ -29164,6 +30203,9 @@ public Builder mergeFrom(boa.types.Ast.Expression other) { if (other.hasTrait()) { mergeTrait(other.getTrait()); } + if (other.hasSafe()) { + setSafe(other.getSafe()); + } this.mergeUnknownFields(other.getUnknownFields()); return this; } @@ -29209,8 +30251,8 @@ public final boolean isInitialized() { return false; } } - if (hasAnnotation()) { - if (!getAnnotation().isInitialized()) { + for (int i = 0; i < getModifiersCount(); i++) { + if (!getModifiers(i).isInitialized()) { return false; } @@ -30780,157 +31822,316 @@ public boa.types.Ast.DeclarationOrBuilder getAnonDeclarationOrBuilder() { return anonDeclarationBuilder_; } - // optional .boa.types.Modifier annotation = 12; - private boa.types.Ast.Modifier annotation_ = boa.types.Ast.Modifier.getDefaultInstance(); - private com.google.protobuf.SingleFieldBuilder< - boa.types.Ast.Modifier, boa.types.Ast.Modifier.Builder, boa.types.Ast.ModifierOrBuilder> annotationBuilder_; + // repeated .boa.types.Modifier modifiers = 12; + private java.util.List modifiers_ = + java.util.Collections.emptyList(); + private void ensureModifiersIsMutable() { + if (!((bitField0_ & 0x00000800) == 0x00000800)) { + modifiers_ = new java.util.ArrayList(modifiers_); + bitField0_ |= 0x00000800; + } + } + + private com.google.protobuf.RepeatedFieldBuilder< + boa.types.Ast.Modifier, boa.types.Ast.Modifier.Builder, boa.types.Ast.ModifierOrBuilder> modifiersBuilder_; + /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
        ** 13 used to be lambda 
        * 
*/ - public boolean hasAnnotation() { - return ((bitField0_ & 0x00000800) == 0x00000800); + public java.util.List getModifiersList() { + if (modifiersBuilder_ == null) { + return java.util.Collections.unmodifiableList(modifiers_); + } else { + return modifiersBuilder_.getMessageList(); + } } /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
        ** 13 used to be lambda 
        * 
*/ - public boa.types.Ast.Modifier getAnnotation() { - if (annotationBuilder_ == null) { - return annotation_; + public int getModifiersCount() { + if (modifiersBuilder_ == null) { + return modifiers_.size(); } else { - return annotationBuilder_.getMessage(); + return modifiersBuilder_.getCount(); + } + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+       ** 13 used to be lambda 
+       * 
+ */ + public boa.types.Ast.Modifier getModifiers(int index) { + if (modifiersBuilder_ == null) { + return modifiers_.get(index); + } else { + return modifiersBuilder_.getMessage(index); } } /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
        ** 13 used to be lambda 
        * 
*/ - public Builder setAnnotation(boa.types.Ast.Modifier value) { - if (annotationBuilder_ == null) { + public Builder setModifiers( + int index, boa.types.Ast.Modifier value) { + if (modifiersBuilder_ == null) { if (value == null) { throw new NullPointerException(); } - annotation_ = value; + ensureModifiersIsMutable(); + modifiers_.set(index, value); onChanged(); } else { - annotationBuilder_.setMessage(value); + modifiersBuilder_.setMessage(index, value); } - bitField0_ |= 0x00000800; return this; } /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
        ** 13 used to be lambda 
        * 
*/ - public Builder setAnnotation( - boa.types.Ast.Modifier.Builder builderForValue) { - if (annotationBuilder_ == null) { - annotation_ = builderForValue.build(); + public Builder setModifiers( + int index, boa.types.Ast.Modifier.Builder builderForValue) { + if (modifiersBuilder_ == null) { + ensureModifiersIsMutable(); + modifiers_.set(index, builderForValue.build()); onChanged(); } else { - annotationBuilder_.setMessage(builderForValue.build()); + modifiersBuilder_.setMessage(index, builderForValue.build()); } - bitField0_ |= 0x00000800; return this; } /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
        ** 13 used to be lambda 
        * 
*/ - public Builder mergeAnnotation(boa.types.Ast.Modifier value) { - if (annotationBuilder_ == null) { - if (((bitField0_ & 0x00000800) == 0x00000800) && - annotation_ != boa.types.Ast.Modifier.getDefaultInstance()) { - annotation_ = - boa.types.Ast.Modifier.newBuilder(annotation_).mergeFrom(value).buildPartial(); - } else { - annotation_ = value; + public Builder addModifiers(boa.types.Ast.Modifier value) { + if (modifiersBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); } + ensureModifiersIsMutable(); + modifiers_.add(value); onChanged(); } else { - annotationBuilder_.mergeFrom(value); + modifiersBuilder_.addMessage(value); } - bitField0_ |= 0x00000800; return this; } /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
        ** 13 used to be lambda 
        * 
*/ - public Builder clearAnnotation() { - if (annotationBuilder_ == null) { - annotation_ = boa.types.Ast.Modifier.getDefaultInstance(); + public Builder addModifiers( + int index, boa.types.Ast.Modifier value) { + if (modifiersBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureModifiersIsMutable(); + modifiers_.add(index, value); onChanged(); } else { - annotationBuilder_.clear(); + modifiersBuilder_.addMessage(index, value); } - bitField0_ = (bitField0_ & ~0x00000800); return this; } /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
        ** 13 used to be lambda 
        * 
*/ - public boa.types.Ast.Modifier.Builder getAnnotationBuilder() { - bitField0_ |= 0x00000800; - onChanged(); - return getAnnotationFieldBuilder().getBuilder(); + public Builder addModifiers( + boa.types.Ast.Modifier.Builder builderForValue) { + if (modifiersBuilder_ == null) { + ensureModifiersIsMutable(); + modifiers_.add(builderForValue.build()); + onChanged(); + } else { + modifiersBuilder_.addMessage(builderForValue.build()); + } + return this; } /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
        ** 13 used to be lambda 
        * 
*/ - public boa.types.Ast.ModifierOrBuilder getAnnotationOrBuilder() { - if (annotationBuilder_ != null) { - return annotationBuilder_.getMessageOrBuilder(); + public Builder addModifiers( + int index, boa.types.Ast.Modifier.Builder builderForValue) { + if (modifiersBuilder_ == null) { + ensureModifiersIsMutable(); + modifiers_.add(index, builderForValue.build()); + onChanged(); } else { - return annotation_; + modifiersBuilder_.addMessage(index, builderForValue.build()); } + return this; } /** - * optional .boa.types.Modifier annotation = 12; + * repeated .boa.types.Modifier modifiers = 12; * *
        ** 13 used to be lambda 
        * 
*/ - private com.google.protobuf.SingleFieldBuilder< + public Builder addAllModifiers( + java.lang.Iterable values) { + if (modifiersBuilder_ == null) { + ensureModifiersIsMutable(); + super.addAll(values, modifiers_); + onChanged(); + } else { + modifiersBuilder_.addAllMessages(values); + } + return this; + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+       ** 13 used to be lambda 
+       * 
+ */ + public Builder clearModifiers() { + if (modifiersBuilder_ == null) { + modifiers_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000800); + onChanged(); + } else { + modifiersBuilder_.clear(); + } + return this; + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+       ** 13 used to be lambda 
+       * 
+ */ + public Builder removeModifiers(int index) { + if (modifiersBuilder_ == null) { + ensureModifiersIsMutable(); + modifiers_.remove(index); + onChanged(); + } else { + modifiersBuilder_.remove(index); + } + return this; + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+       ** 13 used to be lambda 
+       * 
+ */ + public boa.types.Ast.Modifier.Builder getModifiersBuilder( + int index) { + return getModifiersFieldBuilder().getBuilder(index); + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+       ** 13 used to be lambda 
+       * 
+ */ + public boa.types.Ast.ModifierOrBuilder getModifiersOrBuilder( + int index) { + if (modifiersBuilder_ == null) { + return modifiers_.get(index); } else { + return modifiersBuilder_.getMessageOrBuilder(index); + } + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+       ** 13 used to be lambda 
+       * 
+ */ + public java.util.List + getModifiersOrBuilderList() { + if (modifiersBuilder_ != null) { + return modifiersBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(modifiers_); + } + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+       ** 13 used to be lambda 
+       * 
+ */ + public boa.types.Ast.Modifier.Builder addModifiersBuilder() { + return getModifiersFieldBuilder().addBuilder( + boa.types.Ast.Modifier.getDefaultInstance()); + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+       ** 13 used to be lambda 
+       * 
+ */ + public boa.types.Ast.Modifier.Builder addModifiersBuilder( + int index) { + return getModifiersFieldBuilder().addBuilder( + index, boa.types.Ast.Modifier.getDefaultInstance()); + } + /** + * repeated .boa.types.Modifier modifiers = 12; + * + *
+       ** 13 used to be lambda 
+       * 
+ */ + public java.util.List + getModifiersBuilderList() { + return getModifiersFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilder< boa.types.Ast.Modifier, boa.types.Ast.Modifier.Builder, boa.types.Ast.ModifierOrBuilder> - getAnnotationFieldBuilder() { - if (annotationBuilder_ == null) { - annotationBuilder_ = new com.google.protobuf.SingleFieldBuilder< + getModifiersFieldBuilder() { + if (modifiersBuilder_ == null) { + modifiersBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< boa.types.Ast.Modifier, boa.types.Ast.Modifier.Builder, boa.types.Ast.ModifierOrBuilder>( - annotation_, + modifiers_, + ((bitField0_ & 0x00000800) == 0x00000800), getParentForChildren(), isClean()); - annotation_ = null; + modifiers_ = null; } - return annotationBuilder_; + return modifiersBuilder_; } // optional bool no_parens = 14; @@ -32444,6 +33645,39 @@ public boa.types.Ast.MethodOrBuilder getTraitOrBuilder() { return traitBuilder_; } + // optional bool safe = 30; + private boolean safe_ ; + /** + * optional bool safe = 30; + */ + public boolean hasSafe() { + return ((bitField0_ & 0x02000000) == 0x02000000); + } + /** + * optional bool safe = 30; + */ + public boolean getSafe() { + return safe_; + } + /** + * optional bool safe = 30; + */ + public Builder setSafe(boolean value) { + bitField0_ |= 0x02000000; + safe_ = value; + onChanged(); + return this; + } + /** + * optional bool safe = 30; + */ + public Builder clearSafe() { + bitField0_ = (bitField0_ & ~0x02000000); + safe_ = false; + onChanged(); + return this; + } + // @@protoc_insertion_point(builder_scope:boa.types.Expression) } @@ -32950,6 +34184,14 @@ public enum ModifierKind * */ VOLATILE(15, 13), + /** + * IMPLICIT = 14; + * + *
+       ** Modifier is implicit 
+       * 
+ */ + IMPLICIT(16, 14), ; /** @@ -33088,6 +34330,14 @@ public enum ModifierKind * */ public static final int VOLATILE_VALUE = 13; + /** + * IMPLICIT = 14; + * + *
+       ** Modifier is implicit 
+       * 
+ */ + public static final int IMPLICIT_VALUE = 14; public final int getNumber() { return value; } @@ -33108,6 +34358,7 @@ public static ModifierKind valueOf(int value) { case 11: return STRICTFP; case 12: return TRANSIENT; case 13: return VOLATILE; + case 14: return IMPLICIT; default: return null; } } @@ -33138,7 +34389,7 @@ public ModifierKind findValueByNumber(int number) { } private static final ModifierKind[] VALUES = { - OTHER, VISIBILITY, ANNOTATION, FINAL, CONSTANT, STATIC, SYNCHRONIZED, SYNC, ABSTRACT, SCOPE, GETTER, SETTER, NATIVE, STRICTFP, TRANSIENT, VOLATILE, + OTHER, VISIBILITY, ANNOTATION, FINAL, CONSTANT, STATIC, SYNCHRONIZED, SYNC, ABSTRACT, SCOPE, GETTER, SETTER, NATIVE, STRICTFP, TRANSIENT, VOLATILE, IMPLICIT, }; public static ModifierKind valueOf( @@ -33210,6 +34461,14 @@ public enum Visibility * */ DEFAULT(5, 5), + /** + * INTERNAL = 6; + * + *
+       ** An internal visibility modifier 
+       * 
+ */ + INTERNAL(6, 6), ; /** @@ -33268,6 +34527,14 @@ public enum Visibility * */ public static final int DEFAULT_VALUE = 5; + /** + * INTERNAL = 6; + * + *
+       ** An internal visibility modifier 
+       * 
+ */ + public static final int INTERNAL_VALUE = 6; public final int getNumber() { return value; } @@ -33279,6 +34546,7 @@ public static Visibility valueOf(int value) { case 3: return PROTECTED; case 4: return NAMESPACE; case 5: return DEFAULT; + case 6: return INTERNAL; default: return null; } } @@ -33309,7 +34577,7 @@ public Visibility findValueByNumber(int number) { } private static final Visibility[] VALUES = { - PUBLIC, PRIVATE, PROTECTED, NAMESPACE, PACKAGE, DEFAULT, + PUBLIC, PRIVATE, PROTECTED, NAMESPACE, PACKAGE, DEFAULT, INTERNAL, }; public static Visibility valueOf( @@ -42811,168 +44079,176 @@ public Builder setValueBytes( "ypes.Comment\022\013\n\003key\030\r \001(\005\022\034\n\024fully_quali" + "fied_name\030\016 \001(\t\022\026\n\016declaring_type\030\017 \001(\005\022" + "(\n\nstatements\030\020 \003(\0132\024.boa.types.Statemen" + - "t\"\313\001\n\004Type\022\014\n\004name\030\001 \001(\t\022\034\n\024fully_qualif" + + "t\"\364\001\n\004Type\022\014\n\004name\030\001 \001(\t\022\034\n\024fully_qualif" + "ied_name\030\002 \001(\t\022!\n\004kind\030\003 \002(\0162\023.boa.types" + ".TypeKind\022\n\n\002id\030\004 \001(\t\022\030\n\020declaration_fil" + "e\030\010 \001(\005\022\023\n\013declaration\030\t \001(\005\022\013\n\003key\030\n \001(" + "\005\022,\n\rcomputed_name\030\016 \001(\0132\025.boa.types.Exp", - "ression\"\206\003\n\006Method\022\014\n\004name\030\001 \001(\t\022&\n\tmodi" + - "fiers\030\002 \003(\0132\023.boa.types.Modifier\022$\n\013retu" + - "rn_type\030\003 \001(\0132\017.boa.types.Type\022+\n\022generi" + - "c_parameters\030\004 \003(\0132\017.boa.types.Type\022&\n\ta" + - "rguments\030\005 \003(\0132\023.boa.types.Variable\022(\n\017e" + - "xception_types\030\006 \003(\0132\017.boa.types.Type\022(\n" + - "\nstatements\030\007 \003(\0132\024.boa.types.Statement\022" + - "$\n\010comments\030\010 \003(\0132\022.boa.types.Comment\022\013\n" + - "\003key\030\014 \001(\005\022\026\n\016declaring_type\030\r \001(\005\022,\n\rco" + - "mputed_name\030\016 \001(\0132\025.boa.types.Expression", - "\"\316\002\n\010Variable\022\014\n\004name\030\001 \001(\t\022&\n\rvariable_" + - "type\030\002 \001(\0132\017.boa.types.Type\022&\n\tmodifiers" + - "\030\003 \003(\0132\023.boa.types.Modifier\022*\n\013initializ" + - "er\030\004 \001(\0132\025.boa.types.Expression\022$\n\010comme" + - "nts\030\005 \003(\0132\022.boa.types.Comment\022\013\n\003key\030\t \001" + - "(\005\022\026\n\016declaring_type\030\n \001(\005\022,\n\rcomputed_n" + - "ame\030\013 \001(\0132\025.boa.types.Expression\022\023\n\013doll" + - "ar_sign\030\014 \001(\010\022*\n\013expressions\030\r \003(\0132\025.boa" + - ".types.Expression\"\344\010\n\tStatement\0220\n\004kind\030" + - "\001 \002(\0162\".boa.types.Statement.StatementKin", - "d\022$\n\010comments\030\002 \003(\0132\022.boa.types.Comment\022" + - "(\n\nstatements\030\003 \003(\0132\024.boa.types.Statemen" + - "t\022.\n\017initializations\030\004 \003(\0132\025.boa.types.E" + - "xpression\022)\n\nconditions\030\005 \003(\0132\025.boa.type" + - "s.Expression\022&\n\007updates\030\006 \003(\0132\025.boa.type" + - "s.Expression\0221\n\024variable_declaration\030\007 \001" + - "(\0132\023.boa.types.Variable\0220\n\020type_declarat" + - "ion\030\010 \001(\0132\026.boa.types.Declaration\022*\n\013exp" + - "ressions\030\t \003(\0132\025.boa.types.Expression\022\013\n" + - "\003key\030\014 \001(\005\022\"\n\007methods\030\r \003(\0132\021.boa.types.", - "Method\0222\n\025variable_declarations\030\016 \003(\0132\023." + - "boa.types.Variable\0221\n\021type_declarations\030" + - "\017 \003(\0132\026.boa.types.Declaration\022\r\n\005names\030\020" + - " \003(\t\"\231\004\n\rStatementKind\022\t\n\005OTHER\020\000\022\t\n\005BLO" + - "CK\020\001\022\014\n\010TYPEDECL\020\002\022\016\n\nEXPRESSION\020\003\022\010\n\004EX" + - "PR\020\003\022\020\n\014SYNCHRONIZED\020\004\022\010\n\004SYNC\020\004\022\n\n\006RETU" + - "RN\020\005\022\007\n\003FOR\020\006\022\006\n\002DO\020\007\022\t\n\005WHILE\020\010\022\006\n\002IF\020\t" + - "\022\n\n\006ASSERT\020\n\022\t\n\005BREAK\020\013\022\014\n\010CONTINUE\020\014\022\t\n" + - "\005LABEL\020\r\022\n\n\006SWITCH\020\016\022\010\n\004CASE\020\017\022\007\n\003TRY\020\020\022" + - "\t\n\005THROW\020\021\022\t\n\005CATCH\020\022\022\t\n\005EMPTY\020\023\022\013\n\007FINA", - "LLY\020\024\022\014\n\010DEBUGGER\020\025\022\013\n\007DEFAULT\020\026\022\013\n\007FORE" + - "ACH\020\027\022\t\n\005FORIN\020\030\022\010\n\004WITH\020\031\022\t\n\005SCOPE\020\032\022\013\n" + - "\007DECLARE\020\033\022\n\n\006GLOBAL\020\034\022\010\n\004GOTO\020\035\022\017\n\013INLI" + - "NE_HTML\020\036\022\n\n\006STATIC\020\037\022\010\n\004ECHO\020 \022\021\n\rUSE_N" + - "AMESPACE\020!\022\020\n\014USE_CONSTANT\020\"\022\020\n\014USE_FUNC" + - "TION\020#\022\017\n\013TRAIT_ALIAS\020$\022\024\n\020TRAIT_PRECEDE" + - "NCE\020%\022\r\n\tTRAIT_USE\020&\032\002\020\001\"\350\022\n\nExpression\022" + - "2\n\004kind\030\001 \002(\0162$.boa.types.Expression.Exp" + - "ressionKind\022*\n\013expressions\030\002 \003(\0132\025.boa.t" + - "ypes.Expression\022+\n\016variable_decls\030\003 \003(\0132", - "\023.boa.types.Variable\022!\n\010new_type\030\004 \001(\0132\017" + - ".boa.types.Type\022+\n\022generic_parameters\030\005 " + - "\003(\0132\017.boa.types.Type\022\022\n\nis_postfix\030\006 \001(\010" + - "\022\017\n\007literal\030\007 \001(\t\022\020\n\010variable\030\010 \001(\t\022\016\n\006m" + - "ethod\030\t \001(\t\022*\n\013method_args\030\n \003(\0132\025.boa.t" + - "ypes.Expression\0220\n\020anon_declaration\030\013 \001(" + - "\0132\026.boa.types.Declaration\022\'\n\nannotation\030" + - "\014 \001(\0132\023.boa.types.Modifier\022\021\n\tno_parens\030" + - "\016 \001(\010\022\013\n\003key\030\022 \001(\005\022\'\n\016declaring_type\030\023 \001" + - "(\0132\017.boa.types.Type\022$\n\013return_type\030\024 \001(\013", - "2\017.boa.types.Type\022\"\n\007methods\030\025 \003(\0132\021.boa" + - ".types.Method\022(\n\nstatements\030\026 \003(\0132\024.boa." + - "types.Statement\022\030\n\020is_member_access\030\027 \001(" + - "\010\022\023\n\013dollar_sign\030\030 \001(\010\0220\n\021computed_varia" + - "ble\030\031 \001(\0132\025.boa.types.Expression\022.\n\017comp" + - "uted_method\030\032 \001(\0132\025.boa.types.Expression" + - "\022\021\n\tis_static\030\033 \001(\010\022\020\n\010has_from\030\034 \001(\010\022 \n" + - "\005trait\030\035 \001(\0132\021.boa.types.Method\"\231\014\n\016Expr" + - "essionKind\022\t\n\005OTHER\020\000\022\013\n\007LITERAL\020\001\022\r\n\tVA" + - "RACCESS\020\002\022\013\n\007VARDECL\020\003\022\016\n\nMETHODCALL\020\004\022\010", - "\n\004CAST\020\005\022\017\n\013ARRAYACCESS\020\006\022\r\n\tARRAYINIT\020\007" + - "\022\020\n\014ARRAYLITERAL\020\007\022\017\n\013TYPECOMPARE\020\010\022\007\n\003N" + - "EW\020\t\022\014\n\010NEWARRAY\020\n\022\n\n\006OP_ADD\020\013\022\n\n\006OP_SUB" + - "\020\014\022\013\n\007OP_MULT\020\r\022\n\n\006OP_DIV\020\016\022\n\n\006OP_MOD\020\017\022" + - "\n\n\006OP_INC\020\020\022\n\n\006OP_DEC\020\021\022\016\n\nBIT_LSHIFT\020\022\022" + - "\016\n\nBIT_RSHIFT\020\023\022\026\n\022BIT_UNSIGNEDRSHIFT\020\024\022" + - "\013\n\007BIT_AND\020\025\022\n\n\006BIT_OR\020\026\022\013\n\007BIT_NOT\020\027\022\013\n" + - "\007BIT_XOR\020\030\022\017\n\013LOGICAL_NOT\020\031\022\017\n\013LOGICAL_A" + - "ND\020\032\022\016\n\nLOGICAL_OR\020\033\022\006\n\002EQ\020\034\022\007\n\003NEQ\020\035\022\006\n" + - "\002LT\020\036\022\006\n\002GT\020\037\022\010\n\004LTEQ\020 \022\010\n\004GTEQ\020!\022\017\n\013CON", - "DITIONAL\020\"\022\020\n\014NULLCOALESCE\020#\022\n\n\006ASSIGN\020$" + - "\022\016\n\nASSIGN_ADD\020%\022\016\n\nASSIGN_SUB\020&\022\017\n\013ASSI" + - "GN_MULT\020\'\022\016\n\nASSIGN_DIV\020(\022\016\n\nASSIGN_MOD\020" + - ")\022\021\n\rASSIGN_BITXOR\020*\022\021\n\rASSIGN_BITAND\020+\022" + - "\020\n\014ASSIGN_BITOR\020,\022\021\n\rASSIGN_LSHIFT\020-\022\021\n\r" + - "ASSIGN_RSHIFT\020.\022\031\n\025ASSIGN_UNSIGNEDRSHIFT" + - "\020/\022\016\n\nANNOTATION\0200\022\t\n\005PAREN\0201\022\024\n\020METHOD_" + - "REFERENCE\0202\022\n\n\006LAMBDA\0203\022\017\n\013ANON_METHOD\0204" + - "\022\t\n\005YIELD\0205\022\027\n\023ARRAY_COMPREHENSION\0206\022\t\n\005" + - "EMPTY\0207\022\010\n\004SHEQ\0208\022\t\n\005SHNEQ\0209\022\020\n\014XML_DOTQ", - "UERY\020:\022\022\n\016OBJECT_LITERAL\020;\022\016\n\nMETHODDECL" + - "\020<\022\010\n\004LOOP\020=\022\r\n\tGENERATOR\020>\022\017\n\013XML_LITER" + - "AL\020?\022\022\n\016XML_EXPRESSION\020@\022\023\n\017XML_PROPERTY" + - "REF\020A\022\021\n\rXML_MEMBERREF\020B\022\013\n\007XML_DOT\020C\022\016\n" + - "\nXML_DOTDOT\020D\022\006\n\002IN\020E\022\n\n\006TYPEOF\020F\022\021\n\rREG" + - "EXPLITERAL\020G\022\n\n\006DELETE\020H\022\010\n\004VOID\020I\022\023\n\017HA" + - "SHTABLEACCESS\020J\022\020\n\014ARRAYELEMENT\020K\022\r\n\tOP_" + - "CONCAT\020L\022\n\n\006OP_POW\020M\022\021\n\rASSIGN_CONCAT\020N\022" + - "\016\n\nASSIGN_POW\020O\022\014\n\010BACKTICK\020P\022\r\n\tIDENTIC" + - "AL\020Q\022\020\n\014NOTIDENTICAL\020R\022\016\n\nSTRING_AND\020S\022\r", - "\n\tSTRING_OR\020T\022\016\n\nSTRING_XOR\020U\022\030\n\024OP_THRE" + - "E_WAY_COMPARE\020V\022\r\n\tOP_UNPACK\020W\022\t\n\005QUOTE\020" + - "X\022\020\n\014IGNORE_ERROR\020Y\022\013\n\007REQUIRE\020Z\022\020\n\014REQU" + - "IRE_ONCE\020[\022\013\n\007INCLUDE\020\\\022\020\n\014INCLUDE_ONCE\020" + - "]\022\010\n\004LIST\020^\022\r\n\tREFERENCE\020_\022\016\n\nREFLECTION" + - "\020`\022\t\n\005CLONE\020a\022\017\n\013TRAIT_ALIAS\020b\022\024\n\020TRAIT_" + - "PRECEDENCE\020c\022\021\n\rNAMESPACENAME\020d\032\002\020\001\"\215\005\n\010" + - "Modifier\022.\n\004kind\030\001 \002(\0162 .boa.types.Modif" + - "ier.ModifierKind\0222\n\nvisibility\030\002 \001(\0162\036.b" + - "oa.types.Modifier.Visibility\022\027\n\017annotati", - "on_name\030\003 \001(\t\022\032\n\022annotation_members\030\004 \003(" + - "\t\0220\n\021annotation_values\030\005 \003(\0132\025.boa.types" + - ".Expression\022\r\n\005other\030\006 \001(\t\022\013\n\003key\030\n \001(\005\022" + - "(\n\005scope\030\013 \001(\0162\031.boa.types.Modifier.Scop" + - "e\"\346\001\n\014ModifierKind\022\t\n\005OTHER\020\000\022\016\n\nVISIBIL" + - "ITY\020\001\022\016\n\nANNOTATION\020\002\022\t\n\005FINAL\020\003\022\014\n\010CONS" + - "TANT\020\003\022\n\n\006STATIC\020\004\022\020\n\014SYNCHRONIZED\020\005\022\010\n\004" + - "SYNC\020\005\022\014\n\010ABSTRACT\020\006\022\t\n\005SCOPE\020\007\022\n\n\006GETTE" + - "R\020\010\022\n\n\006SETTER\020\t\022\n\n\006NATIVE\020\n\022\014\n\010STRICTFP\020" + - "\013\022\r\n\tTRANSIENT\020\014\022\014\n\010VOLATILE\020\r\032\002\020\001\"a\n\nVi", - "sibility\022\n\n\006PUBLIC\020\001\022\013\n\007PRIVATE\020\002\022\r\n\tPRO" + - "TECTED\020\003\022\r\n\tNAMESPACE\020\004\022\013\n\007PACKAGE\020\004\022\013\n\007" + - "DEFAULT\020\005\032\002\020\001\"$\n\005Scope\022\007\n\003VAR\020\001\022\007\n\003LET\020\002" + - "\022\t\n\005CONST\020\003\"\352\001\n\007Comment\022,\n\004kind\030\001 \002(\0162\036." + - "boa.types.Comment.CommentKind\022\r\n\005value\030\002" + - " \002(\t\022)\n\010position\030\003 \002(\0132\027.boa.types.Posit" + - "ionInfo\022\013\n\003key\030\007 \001(\005\"j\n\013CommentKind\022\t\n\005O" + - "THER\020\000\022\010\n\004LINE\020\001\022\t\n\005BLOCK\020\002\022\007\n\003DOC\020\003\022\021\n\r" + - "DOCUMENTATION\020\003\022\010\n\004SPEC\020\004\022\021\n\rSPECIFICATI" + - "ON\020\004\032\002\020\001\"{\n\014PositionInfo\022\021\n\tstart_pos\030\001 ", - "\002(\005\022\016\n\006length\030\002 \002(\005\022\022\n\nstart_line\030\003 \002(\005\022" + - "\021\n\tstart_col\030\004 \002(\005\022\020\n\010end_line\030\005 \002(\005\022\017\n\007" + - "end_col\030\006 \002(\005\"\233\001\n\010Document\022\r\n\005title\030\001 \001(" + - "\t\022$\n\010elements\030\002 \003(\0132\022.boa.types.Element\022" + - "$\n\010doc_type\030\003 \001(\0132\022.boa.types.Element\0224\n" + - "\026processing_instruction\030\013 \003(\0132\024.boa.type" + - "s.Attribute\"\267\004\n\007Element\022\013\n\003tag\030\001 \002(\t\022,\n\004" + - "kind\030\002 \002(\0162\036.boa.types.Element.ElementKi" + - "nd\022$\n\010elements\030\003 \003(\0132\022.boa.types.Element" + - "\022\014\n\004text\030\004 \003(\t\022\014\n\004data\030\005 \003(\t\022(\n\nattribut", - "es\030\006 \003(\0132\024.boa.types.Attribute\022$\n\006script" + - "\030\007 \001(\0132\024.boa.types.Namespace\022!\n\003php\030\010 \001(" + - "\0132\024.boa.types.Namespace\022%\n\010var_decl\030\t \003(" + - "\0132\023.boa.types.Variable\022\r\n\005title\030\n \001(\t\0224\n" + - "\026processing_instruction\030\013 \003(\0132\024.boa.type" + - "s.Attribute\"\317\001\n\013ElementKind\022\t\n\005OTHER\020\000\022\t" + - "\n\005BLOCK\020\001\022\013\n\007IN_LINE\020\002\022\010\n\004FORM\020\003\022\014\n\010DOC_" + - "TYPE\020\004\022\017\n\013STYLE_SHEET\020\005\022\r\n\tPAGE_RULE\020\006\022\016" + - "\n\nSTYLE_RULE\020\007\022\022\n\016FONT_FACE_RULE\020\010\022\016\n\nME" + - "DIA_RULE\020\t\022\017\n\013MEDIA_QUERY\020\n\022\017\n\013IMPORT_RU", - "LE\020\013\022\017\n\013XML_ELEMENT\020\014\"\'\n\tAttribute\022\013\n\003ke" + - "y\030\001 \002(\t\022\r\n\005value\030\002 \002(\t*\303\001\n\010TypeKind\022\t\n\005O" + - "THER\020\000\022\t\n\005CLASS\020\001\022\r\n\tINTERFACE\020\002\022\r\n\tANON" + - "YMOUS\020\003\022\010\n\004ANON\020\003\022\n\n\006STRUCT\020\004\022\010\n\004ENUM\020\005\022" + - "\017\n\013ENUMERATION\020\005\022\016\n\nANNOTATION\020\006\022\014\n\010DELE" + - "GATE\020\007\022\013\n\007GENERIC\020\010\022\t\n\005TRAIT\020\t\022\r\n\tPRIMIT" + - "IVE\020\n\022\t\n\005ARRAY\020\013\032\002\020\001B\002H\001" + "ression\022\'\n\010delegate\030\017 \001(\0132\025.boa.types.Ex" + + "pression\"\331\003\n\006Method\022\014\n\004name\030\001 \001(\t\022&\n\tmod" + + "ifiers\030\002 \003(\0132\023.boa.types.Modifier\022$\n\013ret" + + "urn_type\030\003 \001(\0132\017.boa.types.Type\022+\n\022gener" + + "ic_parameters\030\004 \003(\0132\017.boa.types.Type\022&\n\t" + + "arguments\030\005 \003(\0132\023.boa.types.Variable\022(\n\017" + + "exception_types\030\006 \003(\0132\017.boa.types.Type\022(" + + "\n\nstatements\030\007 \003(\0132\024.boa.types.Statement" + + "\022$\n\010comments\030\010 \003(\0132\022.boa.types.Comment\022\013" + + "\n\003key\030\014 \001(\005\022\026\n\016declaring_type\030\r \001(\005\022,\n\rc", + "omputed_name\030\016 \001(\0132\025.boa.types.Expressio" + + "n\022)\n\nexpression\030\017 \001(\0132\025.boa.types.Expres" + + "sion\022&\n\rreceiver_type\030\020 \001(\0132\017.boa.types." + + "Type\"\316\002\n\010Variable\022\014\n\004name\030\001 \001(\t\022&\n\rvaria" + + "ble_type\030\002 \001(\0132\017.boa.types.Type\022&\n\tmodif" + + "iers\030\003 \003(\0132\023.boa.types.Modifier\022*\n\013initi" + + "alizer\030\004 \001(\0132\025.boa.types.Expression\022$\n\010c" + + "omments\030\005 \003(\0132\022.boa.types.Comment\022\013\n\003key" + + "\030\t \001(\005\022\026\n\016declaring_type\030\n \001(\005\022,\n\rcomput" + + "ed_name\030\013 \001(\0132\025.boa.types.Expression\022\023\n\013", + "dollar_sign\030\014 \001(\010\022*\n\013expressions\030\r \003(\0132\025" + + ".boa.types.Expression\"\344\010\n\tStatement\0220\n\004k" + + "ind\030\001 \002(\0162\".boa.types.Statement.Statemen" + + "tKind\022$\n\010comments\030\002 \003(\0132\022.boa.types.Comm" + + "ent\022(\n\nstatements\030\003 \003(\0132\024.boa.types.Stat" + + "ement\022.\n\017initializations\030\004 \003(\0132\025.boa.typ" + + "es.Expression\022)\n\nconditions\030\005 \003(\0132\025.boa." + + "types.Expression\022&\n\007updates\030\006 \003(\0132\025.boa." + + "types.Expression\0221\n\024variable_declaration" + + "\030\007 \001(\0132\023.boa.types.Variable\0220\n\020type_decl", + "aration\030\010 \001(\0132\026.boa.types.Declaration\022*\n" + + "\013expressions\030\t \003(\0132\025.boa.types.Expressio" + + "n\022\013\n\003key\030\014 \001(\005\022\"\n\007methods\030\r \003(\0132\021.boa.ty" + + "pes.Method\0222\n\025variable_declarations\030\016 \003(" + + "\0132\023.boa.types.Variable\0221\n\021type_declarati" + + "ons\030\017 \003(\0132\026.boa.types.Declaration\022\r\n\005nam" + + "es\030\020 \003(\t\"\231\004\n\rStatementKind\022\t\n\005OTHER\020\000\022\t\n" + + "\005BLOCK\020\001\022\014\n\010TYPEDECL\020\002\022\016\n\nEXPRESSION\020\003\022\010" + + "\n\004EXPR\020\003\022\020\n\014SYNCHRONIZED\020\004\022\010\n\004SYNC\020\004\022\n\n\006" + + "RETURN\020\005\022\007\n\003FOR\020\006\022\006\n\002DO\020\007\022\t\n\005WHILE\020\010\022\006\n\002", + "IF\020\t\022\n\n\006ASSERT\020\n\022\t\n\005BREAK\020\013\022\014\n\010CONTINUE\020" + + "\014\022\t\n\005LABEL\020\r\022\n\n\006SWITCH\020\016\022\010\n\004CASE\020\017\022\007\n\003TR" + + "Y\020\020\022\t\n\005THROW\020\021\022\t\n\005CATCH\020\022\022\t\n\005EMPTY\020\023\022\013\n\007" + + "FINALLY\020\024\022\014\n\010DEBUGGER\020\025\022\013\n\007DEFAULT\020\026\022\013\n\007" + + "FOREACH\020\027\022\t\n\005FORIN\020\030\022\010\n\004WITH\020\031\022\t\n\005SCOPE\020" + + "\032\022\013\n\007DECLARE\020\033\022\n\n\006GLOBAL\020\034\022\010\n\004GOTO\020\035\022\017\n\013" + + "INLINE_HTML\020\036\022\n\n\006STATIC\020\037\022\010\n\004ECHO\020 \022\021\n\rU" + + "SE_NAMESPACE\020!\022\020\n\014USE_CONSTANT\020\"\022\020\n\014USE_" + + "FUNCTION\020#\022\017\n\013TRAIT_ALIAS\020$\022\024\n\020TRAIT_PRE" + + "CEDENCE\020%\022\r\n\tTRAIT_USE\020&\032\002\020\001\"\307\023\n\nExpress", + "ion\0222\n\004kind\030\001 \002(\0162$.boa.types.Expression" + + ".ExpressionKind\022*\n\013expressions\030\002 \003(\0132\025.b" + + "oa.types.Expression\022+\n\016variable_decls\030\003 " + + "\003(\0132\023.boa.types.Variable\022!\n\010new_type\030\004 \001" + + "(\0132\017.boa.types.Type\022+\n\022generic_parameter" + + "s\030\005 \003(\0132\017.boa.types.Type\022\022\n\nis_postfix\030\006" + + " \001(\010\022\017\n\007literal\030\007 \001(\t\022\020\n\010variable\030\010 \001(\t\022" + + "\016\n\006method\030\t \001(\t\022*\n\013method_args\030\n \003(\0132\025.b" + + "oa.types.Expression\0220\n\020anon_declaration\030" + + "\013 \001(\0132\026.boa.types.Declaration\022&\n\tmodifie", + "rs\030\014 \003(\0132\023.boa.types.Modifier\022\021\n\tno_pare" + + "ns\030\016 \001(\010\022\013\n\003key\030\022 \001(\005\022\'\n\016declaring_type\030" + + "\023 \001(\0132\017.boa.types.Type\022$\n\013return_type\030\024 " + + "\001(\0132\017.boa.types.Type\022\"\n\007methods\030\025 \003(\0132\021." + + "boa.types.Method\022(\n\nstatements\030\026 \003(\0132\024.b" + + "oa.types.Statement\022\030\n\020is_member_access\030\027" + + " \001(\010\022\023\n\013dollar_sign\030\030 \001(\010\0220\n\021computed_va" + + "riable\030\031 \001(\0132\025.boa.types.Expression\022.\n\017c" + + "omputed_method\030\032 \001(\0132\025.boa.types.Express" + + "ion\022\021\n\tis_static\030\033 \001(\010\022\020\n\010has_from\030\034 \001(\010", + "\022 \n\005trait\030\035 \001(\0132\021.boa.types.Method\022\014\n\004sa" + + "fe\030\036 \001(\010\"\353\014\n\016ExpressionKind\022\t\n\005OTHER\020\000\022\013" + + "\n\007LITERAL\020\001\022\r\n\tVARACCESS\020\002\022\013\n\007VARDECL\020\003\022" + + "\016\n\nMETHODCALL\020\004\022\010\n\004CAST\020\005\022\017\n\013ARRAYACCESS" + + "\020\006\022\r\n\tARRAYINIT\020\007\022\020\n\014ARRAYLITERAL\020\007\022\017\n\013T" + + "YPECOMPARE\020\010\022\007\n\003NEW\020\t\022\014\n\010NEWARRAY\020\n\022\n\n\006O" + + "P_ADD\020\013\022\n\n\006OP_SUB\020\014\022\013\n\007OP_MULT\020\r\022\n\n\006OP_D" + + "IV\020\016\022\n\n\006OP_MOD\020\017\022\n\n\006OP_INC\020\020\022\n\n\006OP_DEC\020\021" + + "\022\016\n\nBIT_LSHIFT\020\022\022\016\n\nBIT_RSHIFT\020\023\022\026\n\022BIT_" + + "UNSIGNEDRSHIFT\020\024\022\013\n\007BIT_AND\020\025\022\n\n\006BIT_OR\020", + "\026\022\013\n\007BIT_NOT\020\027\022\013\n\007BIT_XOR\020\030\022\017\n\013LOGICAL_N" + + "OT\020\031\022\017\n\013LOGICAL_AND\020\032\022\016\n\nLOGICAL_OR\020\033\022\006\n" + + "\002EQ\020\034\022\007\n\003NEQ\020\035\022\006\n\002LT\020\036\022\006\n\002GT\020\037\022\010\n\004LTEQ\020 " + + "\022\010\n\004GTEQ\020!\022\017\n\013CONDITIONAL\020\"\022\020\n\014NULLCOALE" + + "SCE\020#\022\n\n\006ASSIGN\020$\022\016\n\nASSIGN_ADD\020%\022\016\n\nASS" + + "IGN_SUB\020&\022\017\n\013ASSIGN_MULT\020\'\022\016\n\nASSIGN_DIV" + + "\020(\022\016\n\nASSIGN_MOD\020)\022\021\n\rASSIGN_BITXOR\020*\022\021\n" + + "\rASSIGN_BITAND\020+\022\020\n\014ASSIGN_BITOR\020,\022\021\n\rAS" + + "SIGN_LSHIFT\020-\022\021\n\rASSIGN_RSHIFT\020.\022\031\n\025ASSI" + + "GN_UNSIGNEDRSHIFT\020/\022\016\n\nANNOTATION\0200\022\t\n\005P", + "AREN\0201\022\024\n\020METHOD_REFERENCE\0202\022\n\n\006LAMBDA\0203" + + "\022\017\n\013ANON_METHOD\0204\022\t\n\005YIELD\0205\022\027\n\023ARRAY_CO" + + "MPREHENSION\0206\022\t\n\005EMPTY\0207\022\010\n\004SHEQ\0208\022\t\n\005SH" + + "NEQ\0209\022\020\n\014XML_DOTQUERY\020:\022\022\n\016OBJECT_LITERA" + + "L\020;\022\016\n\nMETHODDECL\020<\022\010\n\004LOOP\020=\022\r\n\tGENERAT" + + "OR\020>\022\017\n\013XML_LITERAL\020?\022\022\n\016XML_EXPRESSION\020" + + "@\022\023\n\017XML_PROPERTYREF\020A\022\021\n\rXML_MEMBERREF\020" + + "B\022\013\n\007XML_DOT\020C\022\016\n\nXML_DOTDOT\020D\022\006\n\002IN\020E\022\n" + + "\n\006TYPEOF\020F\022\021\n\rREGEXPLITERAL\020G\022\n\n\006DELETE\020" + + "H\022\010\n\004VOID\020I\022\023\n\017HASHTABLEACCESS\020J\022\020\n\014ARRA", + "YELEMENT\020K\022\r\n\tOP_CONCAT\020L\022\n\n\006OP_POW\020M\022\021\n" + + "\rASSIGN_CONCAT\020N\022\016\n\nASSIGN_POW\020O\022\014\n\010BACK" + + "TICK\020P\022\r\n\tIDENTICAL\020Q\022\020\n\014NOTIDENTICAL\020R\022" + + "\016\n\nSTRING_AND\020S\022\r\n\tSTRING_OR\020T\022\016\n\nSTRING" + + "_XOR\020U\022\030\n\024OP_THREE_WAY_COMPARE\020V\022\r\n\tOP_U" + + "NPACK\020W\022\t\n\005QUOTE\020X\022\020\n\014IGNORE_ERROR\020Y\022\013\n\007" + + "REQUIRE\020Z\022\020\n\014REQUIRE_ONCE\020[\022\013\n\007INCLUDE\020\\" + + "\022\020\n\014INCLUDE_ONCE\020]\022\010\n\004LIST\020^\022\r\n\tREFERENC" + + "E\020_\022\016\n\nREFLECTION\020`\022\t\n\005CLONE\020a\022\017\n\013TRAIT_" + + "ALIAS\020b\022\024\n\020TRAIT_PRECEDENCE\020c\022\021\n\rNAMESPA", + "CENAME\020d\022\r\n\tSTATEMENT\020e\022\014\n\010TEMPLATE\020f\022\t\n" + + "\005LABEL\020g\022\014\n\010OP_ELVIS\020h\022\n\n\006NOT_IN\020i\022\016\n\nOP" + + "_NOTNULL\020j\032\002\020\001\"\251\005\n\010Modifier\022.\n\004kind\030\001 \002(" + + "\0162 .boa.types.Modifier.ModifierKind\0222\n\nv" + + "isibility\030\002 \001(\0162\036.boa.types.Modifier.Vis" + + "ibility\022\027\n\017annotation_name\030\003 \001(\t\022\032\n\022anno" + + "tation_members\030\004 \003(\t\0220\n\021annotation_value" + + "s\030\005 \003(\0132\025.boa.types.Expression\022\r\n\005other\030" + + "\006 \001(\t\022\013\n\003key\030\n \001(\005\022(\n\005scope\030\013 \001(\0162\031.boa." + + "types.Modifier.Scope\"\364\001\n\014ModifierKind\022\t\n", + "\005OTHER\020\000\022\016\n\nVISIBILITY\020\001\022\016\n\nANNOTATION\020\002" + + "\022\t\n\005FINAL\020\003\022\014\n\010CONSTANT\020\003\022\n\n\006STATIC\020\004\022\020\n" + + "\014SYNCHRONIZED\020\005\022\010\n\004SYNC\020\005\022\014\n\010ABSTRACT\020\006\022" + + "\t\n\005SCOPE\020\007\022\n\n\006GETTER\020\010\022\n\n\006SETTER\020\t\022\n\n\006NA" + + "TIVE\020\n\022\014\n\010STRICTFP\020\013\022\r\n\tTRANSIENT\020\014\022\014\n\010V" + + "OLATILE\020\r\022\014\n\010IMPLICIT\020\016\032\002\020\001\"o\n\nVisibilit" + + "y\022\n\n\006PUBLIC\020\001\022\013\n\007PRIVATE\020\002\022\r\n\tPROTECTED\020" + + "\003\022\r\n\tNAMESPACE\020\004\022\013\n\007PACKAGE\020\004\022\013\n\007DEFAULT" + + "\020\005\022\014\n\010INTERNAL\020\006\032\002\020\001\"$\n\005Scope\022\007\n\003VAR\020\001\022\007" + + "\n\003LET\020\002\022\t\n\005CONST\020\003\"\352\001\n\007Comment\022,\n\004kind\030\001", + " \002(\0162\036.boa.types.Comment.CommentKind\022\r\n\005" + + "value\030\002 \002(\t\022)\n\010position\030\003 \002(\0132\027.boa.type" + + "s.PositionInfo\022\013\n\003key\030\007 \001(\005\"j\n\013CommentKi" + + "nd\022\t\n\005OTHER\020\000\022\010\n\004LINE\020\001\022\t\n\005BLOCK\020\002\022\007\n\003DO" + + "C\020\003\022\021\n\rDOCUMENTATION\020\003\022\010\n\004SPEC\020\004\022\021\n\rSPEC" + + "IFICATION\020\004\032\002\020\001\"{\n\014PositionInfo\022\021\n\tstart" + + "_pos\030\001 \002(\005\022\016\n\006length\030\002 \002(\005\022\022\n\nstart_line" + + "\030\003 \002(\005\022\021\n\tstart_col\030\004 \002(\005\022\020\n\010end_line\030\005 " + + "\002(\005\022\017\n\007end_col\030\006 \002(\005\"\233\001\n\010Document\022\r\n\005tit" + + "le\030\001 \001(\t\022$\n\010elements\030\002 \003(\0132\022.boa.types.E", + "lement\022$\n\010doc_type\030\003 \001(\0132\022.boa.types.Ele" + + "ment\0224\n\026processing_instruction\030\013 \003(\0132\024.b" + + "oa.types.Attribute\"\267\004\n\007Element\022\013\n\003tag\030\001 " + + "\002(\t\022,\n\004kind\030\002 \002(\0162\036.boa.types.Element.El" + + "ementKind\022$\n\010elements\030\003 \003(\0132\022.boa.types." + + "Element\022\014\n\004text\030\004 \003(\t\022\014\n\004data\030\005 \003(\t\022(\n\na" + + "ttributes\030\006 \003(\0132\024.boa.types.Attribute\022$\n" + + "\006script\030\007 \001(\0132\024.boa.types.Namespace\022!\n\003p" + + "hp\030\010 \001(\0132\024.boa.types.Namespace\022%\n\010var_de" + + "cl\030\t \003(\0132\023.boa.types.Variable\022\r\n\005title\030\n", + " \001(\t\0224\n\026processing_instruction\030\013 \003(\0132\024.b" + + "oa.types.Attribute\"\317\001\n\013ElementKind\022\t\n\005OT" + + "HER\020\000\022\t\n\005BLOCK\020\001\022\013\n\007IN_LINE\020\002\022\010\n\004FORM\020\003\022" + + "\014\n\010DOC_TYPE\020\004\022\017\n\013STYLE_SHEET\020\005\022\r\n\tPAGE_R" + + "ULE\020\006\022\016\n\nSTYLE_RULE\020\007\022\022\n\016FONT_FACE_RULE\020" + + "\010\022\016\n\nMEDIA_RULE\020\t\022\017\n\013MEDIA_QUERY\020\n\022\017\n\013IM" + + "PORT_RULE\020\013\022\017\n\013XML_ELEMENT\020\014\"\'\n\tAttribut" + + "e\022\013\n\003key\030\001 \002(\t\022\r\n\005value\030\002 \002(\t*\210\002\n\010TypeKi" + + "nd\022\t\n\005OTHER\020\000\022\t\n\005CLASS\020\001\022\r\n\tINTERFACE\020\002\022" + + "\r\n\tANONYMOUS\020\003\022\010\n\004ANON\020\003\022\n\n\006STRUCT\020\004\022\010\n\004", + "ENUM\020\005\022\017\n\013ENUMERATION\020\005\022\016\n\nANNOTATION\020\006\022" + + "\014\n\010DELEGATE\020\007\022\013\n\007GENERIC\020\010\022\t\n\005TRAIT\020\t\022\r\n" + + "\tPRIMITIVE\020\n\022\t\n\005ARRAY\020\013\022\r\n\tIMMUTABLE\020\014\022\t" + + "\n\005ALIAS\020\r\022\r\n\tSINGLETON\020\016\022\013\n\007DYNAMIC\020\017\022\r\n" + + "\tDELEGATED\020\020\032\002\020\001B\002H\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -43008,13 +44284,13 @@ public com.google.protobuf.ExtensionRegistry assignDescriptors( internal_static_boa_types_Type_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_boa_types_Type_descriptor, - new java.lang.String[] { "Name", "FullyQualifiedName", "Kind", "Id", "DeclarationFile", "Declaration", "Key", "ComputedName", }); + new java.lang.String[] { "Name", "FullyQualifiedName", "Kind", "Id", "DeclarationFile", "Declaration", "Key", "ComputedName", "Delegate", }); internal_static_boa_types_Method_descriptor = getDescriptor().getMessageTypes().get(5); internal_static_boa_types_Method_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_boa_types_Method_descriptor, - new java.lang.String[] { "Name", "Modifiers", "ReturnType", "GenericParameters", "Arguments", "ExceptionTypes", "Statements", "Comments", "Key", "DeclaringType", "ComputedName", }); + new java.lang.String[] { "Name", "Modifiers", "ReturnType", "GenericParameters", "Arguments", "ExceptionTypes", "Statements", "Comments", "Key", "DeclaringType", "ComputedName", "Expression", "ReceiverType", }); internal_static_boa_types_Variable_descriptor = getDescriptor().getMessageTypes().get(6); internal_static_boa_types_Variable_fieldAccessorTable = new @@ -43032,7 +44308,7 @@ public com.google.protobuf.ExtensionRegistry assignDescriptors( internal_static_boa_types_Expression_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_boa_types_Expression_descriptor, - new java.lang.String[] { "Kind", "Expressions", "VariableDecls", "NewType", "GenericParameters", "IsPostfix", "Literal", "Variable", "Method", "MethodArgs", "AnonDeclaration", "Annotation", "NoParens", "Key", "DeclaringType", "ReturnType", "Methods", "Statements", "IsMemberAccess", "DollarSign", "ComputedVariable", "ComputedMethod", "IsStatic", "HasFrom", "Trait", }); + new java.lang.String[] { "Kind", "Expressions", "VariableDecls", "NewType", "GenericParameters", "IsPostfix", "Literal", "Variable", "Method", "MethodArgs", "AnonDeclaration", "Modifiers", "NoParens", "Key", "DeclaringType", "ReturnType", "Methods", "Statements", "IsMemberAccess", "DollarSign", "ComputedVariable", "ComputedMethod", "IsStatic", "HasFrom", "Trait", "Safe", }); internal_static_boa_types_Modifier_descriptor = getDescriptor().getMessageTypes().get(9); internal_static_boa_types_Modifier_fieldAccessorTable = new diff --git a/src/compiled-proto/boa/types/Diff.java b/src/compiled-proto/boa/types/Diff.java index b7acce220..8ea2a9727 100644 --- a/src/compiled-proto/boa/types/Diff.java +++ b/src/compiled-proto/boa/types/Diff.java @@ -746,6 +746,62 @@ public enum FileKind * */ Source_CSS(39, 701), + /** + * SOURCE_KOTLIN_ERROR = 800; + * + *
+       ** The file represents a Kotlin source file that had a parse error 
+       * 
+ */ + SOURCE_KOTLIN_ERROR(41, 800), + /** + * SOURCE_KOTLIN_1_5 = 815; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.5.x+ 
+       * 
+ */ + SOURCE_KOTLIN_1_5(42, 815), + /** + * SOURCE_KOTLIN_1_4 = 814; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.4.x+ 
+       * 
+ */ + SOURCE_KOTLIN_1_4(43, 814), + /** + * SOURCE_KOTLIN_1_3 = 813; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.3.x+ 
+       * 
+ */ + SOURCE_KOTLIN_1_3(44, 813), + /** + * SOURCE_KOTLIN_1_2 = 812; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.2.x+ 
+       * 
+ */ + SOURCE_KOTLIN_1_2(45, 812), + /** + * SOURCE_KOTLIN_1_1 = 811; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.1.x+ 
+       * 
+ */ + SOURCE_KOTLIN_1_1(46, 811), + /** + * SOURCE_KOTLIN_1_0 = 810; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.0.x+ 
+       * 
+ */ + SOURCE_KOTLIN_1_0(47, 810), ; /** @@ -1156,6 +1212,62 @@ public enum FileKind * */ public static final int CSS_ERROR_VALUE = 700; + /** + * SOURCE_KOTLIN_ERROR = 800; + * + *
+       ** The file represents a Kotlin source file that had a parse error 
+       * 
+ */ + public static final int SOURCE_KOTLIN_ERROR_VALUE = 800; + /** + * SOURCE_KOTLIN_1_5 = 815; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.5.x+ 
+       * 
+ */ + public static final int SOURCE_KOTLIN_1_5_VALUE = 815; + /** + * SOURCE_KOTLIN_1_4 = 814; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.4.x+ 
+       * 
+ */ + public static final int SOURCE_KOTLIN_1_4_VALUE = 814; + /** + * SOURCE_KOTLIN_1_3 = 813; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.3.x+ 
+       * 
+ */ + public static final int SOURCE_KOTLIN_1_3_VALUE = 813; + /** + * SOURCE_KOTLIN_1_2 = 812; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.2.x+ 
+       * 
+ */ + public static final int SOURCE_KOTLIN_1_2_VALUE = 812; + /** + * SOURCE_KOTLIN_1_1 = 811; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.1.x+ 
+       * 
+ */ + public static final int SOURCE_KOTLIN_1_1_VALUE = 811; + /** + * SOURCE_KOTLIN_1_0 = 810; + * + *
+       ** The file represents a Kotlin source file that parsed without error as 1.0.x+ 
+       * 
+ */ + public static final int SOURCE_KOTLIN_1_0_VALUE = 810; public final int getNumber() { return value; } @@ -1193,6 +1305,13 @@ public static FileKind valueOf(int value) { case 601: return Source_XML; case 700: return SOURCE_CSS_ERROR; case 701: return Source_CSS; + case 800: return SOURCE_KOTLIN_ERROR; + case 815: return SOURCE_KOTLIN_1_5; + case 814: return SOURCE_KOTLIN_1_4; + case 813: return SOURCE_KOTLIN_1_3; + case 812: return SOURCE_KOTLIN_1_2; + case 811: return SOURCE_KOTLIN_1_1; + case 810: return SOURCE_KOTLIN_1_0; default: return null; } } @@ -1223,7 +1342,7 @@ public FileKind findValueByNumber(int number) { } private static final FileKind[] VALUES = { - OTHER, BINARY, TEXT, XML, SOURCE_JAVA_ERROR, SOURCE_JAVA_JLS2, SOURCE_JAVA_JLS3, SOURCE_JAVA_JLS4, SOURCE_JAVA_JLS8, JAVA_ERROR, JLS2, JLS3, JLS4, JLS8, SOURCE_JS_ERROR, SOURCE_JS_ES1, SOURCE_JS_ES2, SOURCE_JS_ES3, SOURCE_JS_ES5, SOURCE_JS_ES6, SOURCE_JS_ES7, SOURCE_JS_ES8, JS_ERROR, SOURCE_PHP_ERROR, SOURCE_PHP5, SOURCE_PHP5_3, SOURCE_PHP5_4, SOURCE_PHP5_5, SOURCE_PHP5_6, SOURCE_PHP7_0, SOURCE_PHP7_1, PHP_ERROR, SOURCE_HTML_ERROR, Source_HTML, HTML_ERROR, SOURCE_XML_ERROR, Source_XML, XML_ERROR, SOURCE_CSS_ERROR, Source_CSS, CSS_ERROR, + OTHER, BINARY, TEXT, XML, SOURCE_JAVA_ERROR, SOURCE_JAVA_JLS2, SOURCE_JAVA_JLS3, SOURCE_JAVA_JLS4, SOURCE_JAVA_JLS8, JAVA_ERROR, JLS2, JLS3, JLS4, JLS8, SOURCE_JS_ERROR, SOURCE_JS_ES1, SOURCE_JS_ES2, SOURCE_JS_ES3, SOURCE_JS_ES5, SOURCE_JS_ES6, SOURCE_JS_ES7, SOURCE_JS_ES8, JS_ERROR, SOURCE_PHP_ERROR, SOURCE_PHP5, SOURCE_PHP5_3, SOURCE_PHP5_4, SOURCE_PHP5_5, SOURCE_PHP5_6, SOURCE_PHP7_0, SOURCE_PHP7_1, PHP_ERROR, SOURCE_HTML_ERROR, Source_HTML, HTML_ERROR, SOURCE_XML_ERROR, Source_XML, XML_ERROR, SOURCE_CSS_ERROR, Source_CSS, CSS_ERROR, SOURCE_KOTLIN_ERROR, SOURCE_KOTLIN_1_5, SOURCE_KOTLIN_1_4, SOURCE_KOTLIN_1_3, SOURCE_KOTLIN_1_2, SOURCE_KOTLIN_1_1, SOURCE_KOTLIN_1_0, }; public static FileKind valueOf( @@ -2978,14 +3097,14 @@ public Builder clearPreviousIndices() { static { java.lang.String[] descriptorData = { "\n\ndiff.proto\022\tboa.types\032\014shared.proto\032\ta" + - "st.proto\"\232\010\n\013ChangedFile\022%\n\006change\030\001 \002(\016" + + "st.proto\"\304\t\n\013ChangedFile\022%\n\006change\030\001 \002(\016" + "2\025.boa.types.ChangeKind\022-\n\004kind\030\002 \002(\0162\037." + "boa.types.ChangedFile.FileKind\022\014\n\004name\030\003" + " \002(\t\022\013\n\003key\030\004 \002(\004\022\013\n\003ast\030\005 \002(\010\022)\n\010commen" + "ts\030\006 \001(\0132\027.boa.types.CommentsRoot\022&\n\007cha" + "nges\030\007 \003(\0162\025.boa.types.ChangeKind\022\026\n\016pre" + "vious_names\030\010 \003(\t\022\031\n\021previous_versions\030\t" + - " \003(\005\022\030\n\020previous_indices\030\n \003(\005\"\354\005\n\010FileK" + + " \003(\005\022\030\n\020previous_indices\030\n \003(\005\"\226\007\n\010FileK" + "ind\022\t\n\005OTHER\020\000\022\n\n\006BINARY\020\001\022\010\n\004TEXT\020\002\022\007\n\003", "XML\020\003\022\025\n\021SOURCE_JAVA_ERROR\020d\022\024\n\020SOURCE_J" + "AVA_JLS2\020f\022\024\n\020SOURCE_JAVA_JLS3\020g\022\024\n\020SOUR" + @@ -3004,7 +3123,11 @@ public Builder clearPreviousIndices() { "_HTML\020\365\003\022\017\n\nHTML_ERROR\020\364\003\022\025\n\020SOURCE_XML_" + "ERROR\020\330\004\022\017\n\nSource_XML\020\331\004\022\016\n\tXML_ERROR\020\330" + "\004\022\025\n\020SOURCE_CSS_ERROR\020\274\005\022\017\n\nSource_CSS\020\275" + - "\005\022\016\n\tCSS_ERROR\020\274\005\032\002\020\001B\002H\001" + "\005\022\016\n\tCSS_ERROR\020\274\005\022\030\n\023SOURCE_KOTLIN_ERROR" + + "\020\240\006\022\026\n\021SOURCE_KOTLIN_1_5\020\257\006\022\026\n\021SOURCE_KO" + + "TLIN_1_4\020\256\006\022\026\n\021SOURCE_KOTLIN_1_3\020\255\006\022\026\n\021S", + "OURCE_KOTLIN_1_2\020\254\006\022\026\n\021SOURCE_KOTLIN_1_1" + + "\020\253\006\022\026\n\021SOURCE_KOTLIN_1_0\020\252\006\032\002\020\001B\002H\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { diff --git a/src/java/boa/datagen/SeqRepoImporter.java b/src/java/boa/datagen/SeqRepoImporter.java index e0bf8772a..a6c17b409 100644 --- a/src/java/boa/datagen/SeqRepoImporter.java +++ b/src/java/boa/datagen/SeqRepoImporter.java @@ -459,12 +459,14 @@ private synchronized boolean isFiltered(Project project) { // if (project.getStars() < 2 && project.getSize() < 100) // return true; if (project.getProgrammingLanguagesList().contains("Java") + || project.getProgrammingLanguagesList().contains("Kotlin") || project.getProgrammingLanguagesList().contains("JavaScript") || project.getProgrammingLanguagesList().contains("PHP")) return false; final String lang = project.getMainLanguage(); if (lang != null && (lang.equals("Java") + || lang.equals("Kotlin") || lang.equals("JavaScript") || lang.equals("PHP"))) return false; diff --git a/src/java/boa/datagen/forges/github/MetaDataWorker.java b/src/java/boa/datagen/forges/github/MetaDataWorker.java index fb074cc41..16b9df37c 100644 --- a/src/java/boa/datagen/forges/github/MetaDataWorker.java +++ b/src/java/boa/datagen/forges/github/MetaDataWorker.java @@ -305,7 +305,7 @@ private Project storeRepository(final Project project, final int i) { gitDir = new File(gitRootPath + "/" + name); } - if (project.getForked() || !(project.getProgrammingLanguagesList().contains("Java") || project.getProgrammingLanguagesList().contains("JavaScript") || project.getProgrammingLanguagesList().contains("PHP"))) + if (project.getForked() || !(project.getProgrammingLanguagesList().contains("Java") || project.getProgrammingLanguagesList().contains("Kotlin") || project.getProgrammingLanguagesList().contains("JavaScript") || project.getProgrammingLanguagesList().contains("PHP"))) return project; if (!gitDir.exists()) { diff --git a/src/java/boa/datagen/scm/AbstractCommit.java b/src/java/boa/datagen/scm/AbstractCommit.java index 5c0d4f651..143889730 100644 --- a/src/java/boa/datagen/scm/AbstractCommit.java +++ b/src/java/boa/datagen/scm/AbstractCommit.java @@ -1,7 +1,8 @@ /* - * Copyright 2016, Hridesh Rajan, Robert Dyer, Hoan Nguyen + * Copyright 2016-2021, Hridesh Rajan, Robert Dyer, Hoan Nguyen, Samuel W. Flint, * Iowa State University of Science and Technology - * and Bowling Green State University + * Bowling Green State University + * and University of Nebraska Board of Regents * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,8 @@ import java.io.*; import java.util.*; +import com.steadystate.css.dom.CSSStyleSheetImpl; + import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.SequenceFile.Writer; @@ -30,6 +33,7 @@ import org.eclipse.jdt.core.dom.*; import org.eclipse.php.internal.core.PHPVersion; import org.eclipse.php.internal.core.ast.nodes.Program; +import org.jetbrains.kotlin.psi.KtFile; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.mozilla.javascript.CompilerEnvirons; @@ -37,8 +41,6 @@ import org.mozilla.javascript.ast.AstRoot; import org.w3c.css.sac.InputSource; -import com.steadystate.css.dom.CSSStyleSheetImpl; - import boa.types.Ast.ASTRoot; import boa.types.Code.Revision; import boa.types.Diff.ChangedFile; @@ -51,14 +53,17 @@ import boa.datagen.util.CssVisitor; import boa.datagen.util.FileIO; import boa.datagen.util.HtmlVisitor; +import boa.datagen.util.JavaErrorCheckVisitor; import boa.datagen.util.JavaScriptErrorCheckVisitor; import boa.datagen.util.JavaScriptVisitor; import boa.datagen.util.JavaVisitor; +import boa.datagen.util.KotlinVisitor; import boa.datagen.util.PHPErrorCheckVisitor; import boa.datagen.util.PHPVisitor; import boa.datagen.util.Properties; import boa.datagen.util.XMLVisitor; -import boa.datagen.util.JavaErrorCheckVisitor; +import boa.functions.langmode.KotlinLangMode; + /** * @author rdyer @@ -211,11 +216,20 @@ else if (lowerPath.endsWith(".java")) { fb.setKind(FileKind.SOURCE_JAVA_ERROR); if (parseJavaFile(path, fb, getFileContents(path), false)) { if (debugparse) - System.err.println("Accepted " + fb.getKind() + ": revision " + id + ": file " + path); + System.err.println("Accepted " + fb.getKind().toString().substring(7) + ": revision " + id + ": file " + path); } else { if (debugparse) System.err.println("Found Java parse error in: revision " + id + ": file " + path); } + } else if (lowerPath.endsWith(".kt") || lowerPath.endsWith(".kts")) { + fb.setKind(FileKind.SOURCE_KOTLIN_ERROR); + if (parseKotlinFile(path, fb, getFileContents(path), false)) { + if (debugparse) + System.err.println("Accepted " + fb.getKind().toString().substring(7) + ": revision " + id + ": file " + path); + } else { + if (debugparse) + System.err.println("Found Kotlin parse error in: revision " + id + ": file " + path); + } } else if (lowerPath.endsWith(".js")) { final String content = getFileContents(path); @@ -352,7 +366,7 @@ else if (lowerPath.endsWith(".java")) { BytesWritable bw = new BytesWritable(content.getBytes()); connector.contentWriter.append(new LongWritable(connector.contentWriterLen), bw); connector.contentWriterLen += bw.getLength(); - } catch (IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } @@ -544,9 +558,9 @@ private boolean parseJavaScriptFile(final String path, final ChangedFile.Builder final AstRoot cu; try { cu = parser.parse(content, null, 0); - } catch (java.lang.IllegalArgumentException ex) { + } catch (final java.lang.IllegalArgumentException ex) { return false; - } catch (org.mozilla.javascript.EvaluatorException ex) { + } catch (final org.mozilla.javascript.EvaluatorException ex) { return false; } @@ -580,7 +594,7 @@ private boolean parseJavaScriptFile(final String path, final ChangedFile.Builder final BytesWritable bw = new BytesWritable(ast.build().toByteArray()); connector.astWriter.append(new LongWritable(connector.astWriterLen), bw); connector.astWriterLen += bw.getLength(); - } catch (IOException e) { + } catch (final IOException e) { e.printStackTrace(); } // fb.setComments(comments); @@ -593,14 +607,67 @@ private boolean parseJavaScriptFile(final String path, final ChangedFile.Builder } } - public Map getLOC() { - final Map l = new HashMap(); + private final KotlinVisitor visitor = new KotlinVisitor(); - for (final ChangedFile.Builder cf : changedFiles) - if (cf.getChange() != ChangeKind.DELETED) - l.put(cf.getName(), processLOC(cf.getName())); + private boolean parseKotlinFile(final String path, final ChangedFile.Builder fb, final String content, final boolean storeOnError) { + final KtFile theKt; - return l; + try { + theKt = KotlinLangMode.tryparse(path, content, debugparse); + } catch (final Exception e) { + if (debugparse) + System.err.println("Error parsing Kotlin file: " + path + " from: " + projectName); + e.printStackTrace(); + return false; + } + + if (theKt == null) + return false; + + try { + final ASTRoot.Builder ast = ASTRoot.newBuilder(); + + ast.addNamespaces(visitor.getNamespace(theKt)); + + switch (visitor.getAstLevel()) { + case KotlinVisitor.KLS10: + fb.setKind(FileKind.SOURCE_KOTLIN_1_0); + break; + case KotlinVisitor.KLS11: + fb.setKind(FileKind.SOURCE_KOTLIN_1_1); + break; + case KotlinVisitor.KLS12: + fb.setKind(FileKind.SOURCE_KOTLIN_1_2); + break; + case KotlinVisitor.KLS13: + fb.setKind(FileKind.SOURCE_KOTLIN_1_3); + break; + case KotlinVisitor.KLS14: + fb.setKind(FileKind.SOURCE_KOTLIN_1_4); + break; + case KotlinVisitor.KLS15: + fb.setKind(FileKind.SOURCE_KOTLIN_1_5); + break; + default: + fb.setKind(FileKind.SOURCE_KOTLIN_ERROR); + break; + } + + final BytesWritable bw = new BytesWritable(ast.build().toByteArray()); + connector.astWriter.append(new LongWritable(connector.astWriterLen), bw); + connector.astWriterLen += bw.getLength(); + + return true; + } catch (final IOException e) { + if (debug) + e.printStackTrace(); + } catch (final Exception e) { + if (debugparse) + System.err.println("Error visiting Kotlin file: " + path + " from: " + projectName); + e.printStackTrace(); + } + + return false; } private boolean parseJavaFile(final String path, final ChangedFile.Builder fb, final String content, final boolean storeOnError) { @@ -679,6 +746,16 @@ private boolean parseJavaFile(final String path, final ChangedFile.Builder fb, f } } + public Map getLOC() { + final Map l = new HashMap(); + + for (final ChangedFile.Builder cf : changedFiles) + if (cf.getChange() != ChangeKind.DELETED) + l.put(cf.getName(), processLOC(cf.getName())); + + return l; + } + protected String processLOC(final String path) { String loc = ""; diff --git a/src/java/boa/datagen/util/FileIO.java b/src/java/boa/datagen/util/FileIO.java index 48ff97d41..095a3bc77 100644 --- a/src/java/boa/datagen/util/FileIO.java +++ b/src/java/boa/datagen/util/FileIO.java @@ -88,6 +88,8 @@ public static void writeFileContents(File file, String s, boolean append) { } public static final void delete(final File f) throws IOException { + if (!f.exists()) return; + if (f.isDirectory()) for (final File g : f.listFiles()) delete(g); diff --git a/src/java/boa/datagen/util/JavaVisitor.java b/src/java/boa/datagen/util/JavaVisitor.java index d78448f15..1f63366f4 100644 --- a/src/java/boa/datagen/util/JavaVisitor.java +++ b/src/java/boa/datagen/util/JavaVisitor.java @@ -906,7 +906,7 @@ public boolean visit(SingleMemberAnnotation node) { if (expressions.empty()) { boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder(); eb.setKind(boa.types.Ast.Expression.ExpressionKind.ANNOTATION); - eb.setAnnotation(modifiers.pop()); + eb.addModifiers(modifiers.pop()); b.addAnnotationMembers("value"); b.addAnnotationValues(eb.build()); } else { @@ -932,7 +932,7 @@ public boolean visit(NormalAnnotation node) { if (expressions.empty()) { boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder(); eb.setKind(boa.types.Ast.Expression.ExpressionKind.ANNOTATION); - eb.setAnnotation(modifiers.pop()); + eb.addModifiers(modifiers.pop()); b.addAnnotationMembers(pair.getName().getFullyQualifiedName()); b.addAnnotationValues(eb.build()); } else { @@ -1492,7 +1492,7 @@ public boolean visit(ArrayInitializer node) { // FIXME is it only possible from JLS8 boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder(); eb.setKind(boa.types.Ast.Expression.ExpressionKind.ANNOTATION); - eb.setAnnotation(modifiers.pop()); + eb.addModifiers(modifiers.pop()); b.addExpressions(eb.build()); } else { b.addExpressions(expressions.pop()); diff --git a/src/java/boa/datagen/util/KotlinErrorCheckVisitor.java b/src/java/boa/datagen/util/KotlinErrorCheckVisitor.java new file mode 100644 index 000000000..ac9d81048 --- /dev/null +++ b/src/java/boa/datagen/util/KotlinErrorCheckVisitor.java @@ -0,0 +1,46 @@ +/* + * Copyright 2021, Robert Dyer + * and University of Nebraska Board of Regents + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package boa.datagen.util; + +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.impl.source.tree.PsiErrorElementImpl; + +import org.jetbrains.kotlin.psi.KtFile; + +/** + * @author rdyer + */ +public class KotlinErrorCheckVisitor extends PsiElementVisitor { + private boolean hasError = false; + + public boolean hasError(final KtFile kt) { + hasError = kt == null; + if (!hasError) + kt.accept(this); + return hasError; + } + + @Override + public void visitElement(final PsiElement element) { + if (element instanceof PsiErrorElementImpl) + hasError = true; + if (!hasError) + element.acceptChildren(this); + } +} diff --git a/src/java/boa/datagen/util/KotlinVisitor.java b/src/java/boa/datagen/util/KotlinVisitor.java new file mode 100644 index 000000000..c18cd9731 --- /dev/null +++ b/src/java/boa/datagen/util/KotlinVisitor.java @@ -0,0 +1,2104 @@ +/* + * Copyright 2021, Robert Dyer, Samuel W. Flint, + * and University of Nebraska Board of Regents + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.datagen.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import com.intellij.psi.impl.source.tree.LeafPsiElement; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiWhiteSpace; +import org.jetbrains.kotlin.lexer.KtModifierKeywordToken; +import org.jetbrains.kotlin.lexer.KtTokens; +import org.jetbrains.kotlin.psi.*; + +import boa.types.Ast.Declaration; +import boa.types.Ast.Expression; +import boa.types.Ast.Method; +import boa.types.Ast.Modifier; +import boa.types.Ast.Namespace; +import boa.types.Ast.Statement; +import boa.types.Ast.Type; +import boa.types.Ast.TypeKind; +import boa.types.Ast.Variable; + + +/** + * @author rdyer + * @author swflint + */ +public class KotlinVisitor extends KtVisitor { + protected Namespace.Builder b = Namespace.newBuilder(); + + protected Stack> declarations = new Stack>(); + protected Stack> modifiers = new Stack>(); + protected Stack> expressions = new Stack>(); + protected Stack> fields = new Stack>(); + protected Stack> methods = new Stack>(); + protected Stack> statements = new Stack>(); + protected Stack> types = new Stack>(); + + protected Stack expectExpression = new Stack(); + + protected List superClassInitExprs = new ArrayList(); + + public static final int KLS10 = 10; + public static final int KLS11 = 11; + public static final int KLS12 = 12; + public static final int KLS13 = 13; + public static final int KLS14 = 14; + public static final int KLS15 = 15; + protected int astLevel = KLS15; + + protected void reset() { + b = Namespace.newBuilder(); + b.setName(""); + + declarations.clear(); + modifiers.clear(); + expressions.clear(); + fields.clear(); + methods.clear(); + statements.clear(); + types.clear(); + + expectExpression.clear(); + + superClassInitExprs.clear(); + + astLevel = KLS15; + } + + public int getAstLevel() { + return astLevel; + } + + public Namespace getNamespace(final KtFile kt) { + reset(); + if (kt != null) + kt.accept(this); + + return b.build(); + } + + @Override + public void visitElement(final PsiElement element) { + if (element instanceof LeafPsiElement && ((LeafPsiElement)element).getElementType() instanceof KtModifierKeywordToken) + visitModifier((KtModifierKeywordToken)((LeafPsiElement)element).getElementType()); + else + element.acceptChildren(this); + } + + public void visitModifier(final KtModifierKeywordToken m) { + final Modifier.Builder mb = Modifier.newBuilder(); + + switch (m.getValue()) { + case "abstract": + mb.setKind(Modifier.ModifierKind.ABSTRACT); + break; + + case "const": + mb.setKind(Modifier.ModifierKind.STATIC); + break; + + case "final": + mb.setKind(Modifier.ModifierKind.FINAL); + break; + + case "actual": + case "impl": + case "expect": + case "header": + case "fun": + case "reified": + case "open": + case "value": + case "inner": + case "sealed": + case "override": + case "inline": + case "noinline": + case "operator": + case "vararg": + case "tailrec": + case "suspend": + case "in": + case "out": + case "external": + case "infix": + case "crossinline": + case "lateinit": + case "data": + case "enum": + case "companion": + case "annotation": + mb.setKind(Modifier.ModifierKind.OTHER); + mb.setOther(m.getValue()); + break; + + case "public": + mb.setKind(Modifier.ModifierKind.VISIBILITY); + mb.setVisibility(Modifier.Visibility.PUBLIC); + break; + + case "protected": + mb.setKind(Modifier.ModifierKind.VISIBILITY); + mb.setVisibility(Modifier.Visibility.PROTECTED); + break; + + case "private": + mb.setKind(Modifier.ModifierKind.VISIBILITY); + mb.setVisibility(Modifier.Visibility.PRIVATE); + break; + + case "internal": + mb.setKind(Modifier.ModifierKind.VISIBILITY); + mb.setVisibility(Modifier.Visibility.INTERNAL); + break; + + default: + System.err.println("===> UNKNOWN MODIFIER: " + m.getValue()); + mb.setKind(Modifier.ModifierKind.OTHER); + mb.setOther(m.getValue()); + break; + } + + modifiers.peek().add(mb.build()); + } + + @Override + public Void visitKtFile(final KtFile f, final Void v) { + modifiers.push(new ArrayList()); + declarations.push(new ArrayList()); + fields.push(new ArrayList()); + methods.push(new ArrayList()); + statements.push(new ArrayList()); + expectExpression.push(false); + + f.acceptChildren(this); + + expectExpression.pop(); + b.addAllStatements(statements.pop()); + b.addAllMethods(methods.pop()); + b.addAllVariables(fields.pop()); + b.addAllDeclarations(declarations.pop()); + b.addAllModifiers(modifiers.pop()); + + return null; + } + + @Override + public Void visitScript(final KtScript s, final Void v) { + modifiers.push(new ArrayList()); + declarations.push(new ArrayList()); + fields.push(new ArrayList()); + methods.push(new ArrayList()); + statements.push(new ArrayList()); + expectExpression.push(false); + + s.acceptChildren(this); + + expectExpression.pop(); + b.addAllStatements(statements.pop()); + b.addAllMethods(methods.pop()); + b.addAllVariables(fields.pop()); + b.addAllDeclarations(declarations.pop()); + b.addAllModifiers(modifiers.pop()); + + return null; + } + + @Override + public Void visitPackageDirective(final KtPackageDirective pkg, final Void v) { + b.setName(pkg.getQualifiedName()); + if (pkg.getModifierList() != null) { + modifiers.push(new ArrayList()); + pkg.getModifierList().accept(this, v); + b.addAllModifiers(modifiers.pop()); + } + return null; + } + + @Override + public Void visitImportDirective(final KtImportDirective imprt, final Void v) { + final StringBuilder sb = new StringBuilder(); + + sb.append(imprt.getImportedFqName().toString()); + + if (imprt.isAllUnder()) + sb.append(".*"); + + if (imprt.getAliasName() != null) + sb.append(" as " + imprt.getAliasName()); + + b.addImports(sb.toString()); + return null; + } + + @Override + public Void visitAnnotationEntry(final KtAnnotationEntry entry, final Void v) { + final Modifier.Builder mb = Modifier.newBuilder(); + + mb.setKind(Modifier.ModifierKind.ANNOTATION); + + if (entry.getUseSiteTarget() != null) + mb.setOther(entry.getUseSiteTarget().getText()); + mb.setAnnotationName(entry.getCalleeExpression().getText()); + + if (entry.getValueArgumentList() != null) { + expressions.push(new ArrayList()); + entry.getValueArgumentList().accept(this, v); + mb.addAllAnnotationValues(expressions.pop()); + } + + modifiers.peek().add(mb.build()); + return null; + } + + @Override + public Void visitObjectDeclaration(final KtObjectDeclaration d, final Void v) { + final Declaration.Builder db = Declaration.newBuilder(); + + if (d.getName() != null) + db.setName(d.getName()); + else + db.setName(""); + + db.setKind(TypeKind.SINGLETON); + + expectExpression.push(false); + + for(final KtTypeParameter p : d.getTypeParameters()) + db.addGenericParameters(buildGenericParam(p, d.getTypeConstraints())); + + modifiers.push(new ArrayList()); + fields.push(new ArrayList()); + methods.push(new ArrayList()); + declarations.push(new ArrayList()); + types.push(new ArrayList()); + + if (d.isCompanion()) + db.addModifiers(Modifier.newBuilder() + .setKind(Modifier.ModifierKind.OTHER) + .setOther("COMPANION") + .build()); + + d.acceptChildren(this, v); + + db.addAllParents(types.pop()); + db.addAllNestedDeclarations(declarations.pop()); + db.addAllMethods(methods.pop()); + db.addAllFields(fields.pop()); + db.addAllModifiers(modifiers.pop()); + + expectExpression.pop(); + + declarations.peek().add(db.build()); + return null; + } + + @Override + public Void visitDestructuringDeclaration(final KtDestructuringDeclaration d, final Void v) { + if (expectExpression.peek()) { + fields.push(new ArrayList()); + expressions.push(new ArrayList()); + } + + for (final KtDestructuringDeclarationEntry entry : d.getEntries()) + entry.accept(this, v); + + if (d.hasInitializer()) { + expectExpression.push(true); + d.getInitializer().accept(this, v); + expectExpression.pop(); + } + + if (expectExpression.peek()) { + final Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.VARDECL); + + eb.addAllExpressions(expressions.pop()); + eb.addAllVariableDecls(fields.pop()); + + expressions.peek().add(eb.build()); + } + + return null; + } + + @Override + public Void visitDestructuringDeclarationEntry(final KtDestructuringDeclarationEntry n, final Void v) { + final Variable.Builder vb = Variable.newBuilder(); + + vb.setName(n.getName()); + + if (n.getTypeReference() != null) + vb.setVariableType(typeFromTypeRef(n.getTypeReference())); + + if (n.getValOrVarKeyword() == null) + vb.addModifiers(Modifier.newBuilder() + .setKind(Modifier.ModifierKind.IMPLICIT) + .build()); + if (!n.isVar()) + vb.addModifiers(Modifier.newBuilder() + .setKind(Modifier.ModifierKind.FINAL) + .build()); + + if (n.getModifierList() != null) { + modifiers.push(new ArrayList()); + n.getModifierList().accept(this, v); + vb.addAllModifiers(modifiers.pop()); + } + + fields.peek().add(vb.build()); + return null; + } + + @Override + public Void visitTypeAlias(final KtTypeAlias ta, final Void v) { + modifiers.push(new ArrayList()); + if (ta.getModifierList() != null) + ta.getModifierList().accept(this, v); + + types.push(new ArrayList()); + for (final KtTypeParameter p : ta.getTypeParameters()) + types.peek().add(buildGenericParam(p, ta.getTypeConstraints())); + + declarations.peek().add(Declaration.newBuilder() + .setKind(TypeKind.ALIAS) + .setName(ta.getName()) + .addParents(typeFromTypeRef(ta.getTypeReference())) + .addAllModifiers(modifiers.pop()) + .addAllGenericParameters(types.pop()) + .build()); + return null; + } + + @Override + public Void visitEnumEntry(final KtEnumEntry n, final Void v) { + final Variable.Builder vb = Variable.newBuilder(); + vb.setName(n.getNameAsSafeName().asString()); + vb.addModifiers(Modifier.newBuilder() + .setKind(Modifier.ModifierKind.IMPLICIT) + .build()); + + final String parentName = ((KtClassOrObject) (n.getParent().getParent())).getNameAsSafeName().asString(); + final Type theType = Type.newBuilder() + .setKind(TypeKind.ENUM) + .setName(parentName) + .build(); + vb.setVariableType(theType); + + if (n.getModifierList() != null) { + modifiers.push(new ArrayList()); + n.getModifierList().accept(this, v); + vb.addAllModifiers(modifiers.pop()); + } + + if (n.hasInitializer()) { + if (n.getInitializerList() != null) { + for (final KtSuperTypeListEntry st : n.getInitializerList().getInitializers()) { + types.push(new ArrayList()); + st.accept(this, v); + vb.addExpressions(Expression.newBuilder() + .setKind(Expression.ExpressionKind.NEW) + .setNewType(theType) + .addAllExpressions(superClassInitExprs)); + superClassInitExprs.clear(); + } + } + } + + if (n.getBody() != null) { + final Declaration.Builder db = Declaration.newBuilder(); + + db.setName(parentName); + db.setKind(TypeKind.ENUM); + + fields.push(new ArrayList()); + methods.push(new ArrayList()); + modifiers.push(new ArrayList()); + declarations.push(new ArrayList()); + + n.getBody().accept(this, v); + + db.addAllNestedDeclarations(declarations.pop()); + db.addAllModifiers(modifiers.pop()); + db.addAllMethods(methods.pop()); + db.addAllFields(fields.pop()); + + vb.setInitializer(Expression.newBuilder() + .setKind(Expression.ExpressionKind.NEW) + .setAnonDeclaration(db.build()) + .build()); + } + + fields.peek().add(vb.build()); + return null; + } + + @Override + public Void visitDelegatedSuperTypeEntry(final KtDelegatedSuperTypeEntry n, final Void v) { + final Type.Builder tb = Type.newBuilder(); + + tb.setKind(TypeKind.DELEGATED); + + tb.setName(n.getTypeReference().getText()); + + if (n.getDelegateExpression() != null) { + expressions.push(new ArrayList()); + expectExpression.push(true); + n.getDelegateExpression().accept(this, v); + expectExpression.pop(); + tb.setDelegate(expressions.pop().get(0)); + } + + types.peek().add(tb.build()); + + return null; + } + + @Override + public Void visitSuperTypeCallEntry(final KtSuperTypeCallEntry n, final Void v) { + if (n.getTypeReference() == null) + return null; + + types.peek().add(typeFromTypeRef(n.getTypeReference(), TypeKind.CLASS)); + + final Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.METHODCALL); + eb.setMethod(n.getTypeReference().getText()); + + if (n.getValueArgumentList() != null) { + expressions.push(new ArrayList()); + n.getValueArgumentList().accept(this, v); + eb.addAllMethodArgs(expressions.pop()); + } + + superClassInitExprs.add(eb.build()); + return null; + } + + @Override + public Void visitSuperTypeEntry(final KtSuperTypeEntry n, final Void v) { + if (n.getTypeReference() != null) + types.peek().add(typeFromTypeRef(n.getTypeReference(), TypeKind.CLASS)); + return null; + } + + @Override + public Void visitSimpleNameExpression(final KtSimpleNameExpression expr, final Void v) { + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.VARACCESS) + .setVariable(expr.getReferencedName()).build()); + return null; + } + + @Override + public Void visitLabeledExpression(final KtLabeledExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.LABEL); + + sb.addExpressions(Expression.newBuilder() + .setKind(Expression.ExpressionKind.LABEL) + .setLiteral(expr.getNameIdentifier().getText()) + .build()); + + if (expr.getBaseExpression() != null) { + expectExpression.push(true); + expressions.push(new ArrayList()); + expr.getBaseExpression().accept(this, v); + sb.addAllExpressions(expressions.pop()); + expectExpression.pop(); + } + + pushStatementOrExpr(sb); + return null; + } + + // No need for visitPostfixExpression/visitPrefixExpression, this handles them both quite easily. + @Override + public Void visitUnaryExpression(final KtUnaryExpression expr, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + expressions.push(new ArrayList()); + if (expr.getBaseExpression() != null) + expr.getBaseExpression().accept(this, v); + eb.addAllExpressions(expressions.pop()); + + switch(expr.getOperationToken().toString()) { + case "MINUSMINUS": + eb.setKind(Expression.ExpressionKind.OP_DEC); + break; + case "PLUS": + eb.setKind(Expression.ExpressionKind.OP_ADD); + break; + case "EXCLEXCL": + eb.setKind(Expression.ExpressionKind.OP_NOTNULL); + break; + case "PLUSPLUS": + eb.setKind(Expression.ExpressionKind.OP_INC); + break; + case "MINUS": + eb.setKind(Expression.ExpressionKind.OP_SUB); + break; + case "EXCL": + eb.setKind(Expression.ExpressionKind.LOGICAL_NOT); + break; + default: + eb.setKind(Expression.ExpressionKind.OTHER); + eb.setLiteral(expr.getOperationToken().toString()); + System.err.println("===> UNKNOWN UNARY OPERATOR: " + expr.getOperationToken().toString()); + break; + } + + if (expr instanceof KtPostfixExpression) + eb.setIsPostfix(true); + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitReturnExpression(final KtReturnExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.RETURN); + + expressions.push(new ArrayList()); + expr.acceptChildren(this, v); + sb.addAllExpressions(expressions.pop()); + + if (expr.getLabelName() != null) + sb.addExpressions(Expression.newBuilder() + .setLiteral(expr.getLabelName()) + .setKind(Expression.ExpressionKind.LABEL) + .build()); + + pushStatementOrExpr(sb); + return null; + } + + @Override + public Void visitThrowExpression(final KtThrowExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.THROW); + + expressions.push(new ArrayList()); + expr.acceptChildren(this, v); + sb.addAllExpressions(expressions.pop()); + + pushStatementOrExpr(sb); + return null; + } + + @Override + public Void visitIfExpression(final KtIfExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.IF); + + if (expr.getCondition() != null) { + expressions.push(new ArrayList()); + expr.getCondition().accept(this, v); + sb.addAllConditions(expressions.pop()); + } + + statements.push(new ArrayList()); + expressions.push(new ArrayList()); + if (expr.getThen() != null) + expr.getThen().accept(this, v); + else + pushEmpty(); + for (final Expression e : expressions.pop()) + sb.addStatements(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(e) + .build()); + sb.addAllStatements(statements.pop()); + + if (expr.getElse() != null || expr.getElseKeyword() != null) { + statements.push(new ArrayList()); + expressions.push(new ArrayList()); + if (expr.getElse() != null) + expr.getElse().accept(this, v); + else + pushEmpty(); + for (final Expression e : expressions.pop()) + sb.addStatements(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(e) + .build()); + sb.addAllStatements(statements.pop()); + } + + pushStatementOrExpr(sb); + return null; + } + + @Override + public Void visitCollectionLiteralExpression(final KtCollectionLiteralExpression expr, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.ARRAYLITERAL); + + expressions.push(new ArrayList()); + expr.acceptChildren(this, v); + eb.addAllExpressions(expressions.pop()); + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitForExpression(final KtForExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.FOREACH); + + expectExpression.push(false); + if (expr.getDestructuringDeclaration() != null) { + fields.push(new ArrayList()); + expressions.push(new ArrayList()); + expr.getDestructuringDeclaration().accept(this, v); + sb.addAllInitializations(expressions.pop()); + sb.addAllVariableDeclarations(fields.pop()); + } else if (expr.getLoopParameter() != null) { + fields.push(new ArrayList()); + expr.getLoopParameter().accept(this, v); + sb.addAllVariableDeclarations(fields.pop()); + } + expectExpression.pop(); + + if (expr.getLoopRange() != null) { + expressions.push(new ArrayList()); + expr.getLoopRange().accept(this, v); + sb.addAllInitializations(expressions.pop()); + } + + expectExpression.push(false); + statements.push(new ArrayList()); + expressions.push(new ArrayList()); + if (expr.getBody() != null) + expr.getBody().accept(this, v); + else + pushEmpty(); + for (final Expression e : expressions.pop()) + sb.addStatements(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(e) + .build()); + sb.addAllStatements(statements.pop()); + expectExpression.pop(); + + pushStatementOrExpr(sb); + return null; + } + + @Override + public Void visitWhileExpression(final KtWhileExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.WHILE); + + expressions.push(new ArrayList()); + expr.getCondition().accept(this, v); + sb.addAllConditions(expressions.pop()); + + statements.push(new ArrayList()); + expressions.push(new ArrayList()); + if (expr.getBody() != null) + expr.getBody().accept(this, v); + else + pushEmpty(); + for (final Expression e : expressions.pop()) + sb.addStatements(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(e) + .build()); + sb.addAllStatements(statements.pop()); + + pushStatementOrExpr(sb); + return null; + } + + @Override + public Void visitDoWhileExpression(final KtDoWhileExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.DO); + + expressions.push(new ArrayList()); + expr.getCondition().accept(this, v); + sb.addAllConditions(expressions.pop()); + + statements.push(new ArrayList()); + expressions.push(new ArrayList()); + if (expr.getBody() != null) + expr.getBody().accept(this, v); + else + pushEmpty(); + for (final Expression e : expressions.pop()) + sb.addStatements(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(e) + .build()); + sb.addAllStatements(statements.pop()); + + pushStatementOrExpr(sb); + return null; + } + + @Override + public Void visitLambdaExpression(final KtLambdaExpression expr, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.LAMBDA); + + if (expr.hasDeclaredReturnType()) + eb.setReturnType(typeFromTypeRef(expr.getFunctionLiteral().getTypeReference())); + + fields.push(new ArrayList()); + expectExpression.push(false); + for (final KtParameter p : expr.getValueParameters()) + p.accept(this, v); + expectExpression.pop(); + eb.addAllVariableDecls(fields.pop()); + + if (expr.getBodyExpression() != null) { + expectExpression.push(true); + expressions.push(new ArrayList()); + statements.push(new ArrayList()); + expr.getBodyExpression().accept(this, v); + eb.addAllStatements(statements.pop()); + eb.addAllExpressions(expressions.pop()); + expectExpression.pop(); + } + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitAnnotatedExpression(final KtAnnotatedExpression expr, final Void v) { + modifiers.push(new ArrayList()); + for (final KtAnnotationEntry ann : expr.getAnnotationEntries()) + ann.accept(this, v); + + final List list = new ArrayList(); + expressions.push(list); + final List stmtList = new ArrayList(); + statements.push(stmtList); + expectExpression.push(true); + expr.getBaseExpression().accept(this, v); + statements.pop(); + expectExpression.pop(); + + final Expression.Builder eb; + if (list.size() == 0) { + expressions.pop(); + eb = Expression.newBuilder(); + eb.setKind(Expression.ExpressionKind.STATEMENT); + eb.addStatements(stmtList.get(0)); + } else { + eb = Expression.newBuilder(expressions.pop().get(0)); + } + + eb.addAllModifiers(modifiers.pop()); + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitArrayAccessExpression(final KtArrayAccessExpression expr, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.ARRAYACCESS); + + expressions.push(new ArrayList()); + expr.acceptChildren(this, v); + eb.addAllExpressions(expressions.pop()); + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitDoubleColonExpression(final KtDoubleColonExpression expr, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.METHOD_REFERENCE); + eb.setMethod(expr.getText()); + + if (expr.getReceiverExpression() != null) { + expressions.push(new ArrayList()); + expr.getReceiverExpression().accept(this, v); + eb.addAllExpressions(expressions.pop()); + } + + expressions.peek().add(eb.build()); + return null; + } + + protected int getQuestionsCount(final KtCallableReferenceExpression expr) { + int count = 0; + ASTNode child = expr.getNode().getFirstChildNode(); + while (child != null) { + if (KtTokens.QUEST == child.getElementType()) + count++; + child = child.getTreeNext(); + } + return count; + } + + + @Override + public Void visitCallableReferenceExpression(final KtCallableReferenceExpression expr, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.METHOD_REFERENCE); + eb.setMethod(expr.getCallableReference().getText()); + + if (expr.getReceiverExpression() != null) { + expressions.push(new ArrayList()); + expr.getReceiverExpression().accept(this, v); + if (expr.getHasQuestionMarks()) { + String questions = ""; + for (int i = 0; i < getQuestionsCount(expr); i++) + questions += "?"; + + final Expression.Builder eb2 = Expression.newBuilder(expressions.peek().get(0)); + + if ((eb2.getKind() == Expression.ExpressionKind.METHODCALL) || (eb2.getKind() == Expression.ExpressionKind.METHOD_REFERENCE)) + eb2.setMethod(eb2.getMethod() + questions); + else + eb2.setVariable(eb2.getVariable() + questions); + eb.addExpressions(eb2.build()); + expressions.pop(); + } else { + eb.addAllExpressions(expressions.pop()); + } + } + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitArgument(final KtValueArgument arg, final Void v) { + expectExpression.push(true); + arg.getArgumentExpression().accept(this, v); + expectExpression.pop(); + + if (arg.isSpread()) { + final List list = expressions.peek(); + list.add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.OP_MULT) + .addExpressions(list.remove(list.size() - 1)) + .build()); + } + + if (arg.isNamed()) { + final List list = expressions.peek(); + list.add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.ASSIGN) + .addExpressions(Expression.newBuilder() + .setKind(Expression.ExpressionKind.VARACCESS) + .setVariable(arg.getArgumentName().getText()) + .build()) + .addExpressions(list.remove(list.size() - 1)) + .build()); + } + + return null; + } + + private Expression.Builder buildQualifiedExpr(final KtQualifiedExpression expr, final Void v) { + Expression.Builder eb = Expression.newBuilder(); + + final KtExpression rcvr = expr.getReceiverExpression(); + final KtExpression sel = expr.getSelectorExpression(); + + if (sel instanceof KtCallExpression || sel instanceof KtLambdaExpression) { + expressions.push(new ArrayList()); + sel.accept(this, v); + eb = Expression.newBuilder(expressions.pop().get(0)); + + expressions.push(new ArrayList()); + rcvr.accept(this, v); + eb.addAllExpressions(expressions.pop()); + } else { + eb.setKind(Expression.ExpressionKind.VARACCESS); + eb.setVariable(sel.getText()); + + expressions.push(new ArrayList()); + rcvr.accept(this, v); + eb.addAllExpressions(expressions.pop()); + } + + return eb; + } + + @Override + public Void visitDotQualifiedExpression(final KtDotQualifiedExpression expr, final Void v) { + expressions.peek().add(buildQualifiedExpr(expr, v).build()); + return null; + } + + @Override + public Void visitSafeQualifiedExpression(final KtSafeQualifiedExpression expr, final Void v) { + expressions.peek().add(buildQualifiedExpr(expr, v).setSafe(true).build()); + return null; + } + + @Override + public Void visitObjectLiteralExpression(final KtObjectLiteralExpression expr, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.NEW); + + declarations.push(new ArrayList()); + expr.getObjectDeclaration().accept(this, v); + final Declaration objLiteral = declarations.pop().get(0); + + eb.setAnonDeclaration(objLiteral); + + if (objLiteral.getParentsCount() > 0) + eb.setNewType(Type.newBuilder(objLiteral.getParents(0)).build()); + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitBlockExpression(final KtBlockExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.BLOCK); + + for (final KtExpression e : expr.getStatements()) { + declarations.push(new ArrayList()); + methods.push(new ArrayList()); + statements.push(new ArrayList()); + expressions.push(new ArrayList()); + expectExpression.push(e instanceof KtProperty); + + e.accept(this, v); + + expectExpression.pop(); + for (final Expression ex : expressions.pop()) + sb.addStatements(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(ex) + .build()); + sb.addAllStatements(statements.pop()); + sb.addAllMethods(methods.pop()); + sb.addAllTypeDeclarations(declarations.pop()); + } + + statements.peek().add(sb.build()); + return null; + } + + @Override + public Void visitTryExpression(final KtTryExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.TRY); + + statements.push(new ArrayList()); + expectExpression.push(false); + + expr.getTryBlock().accept(this, v); + for (final KtCatchClause c : expr.getCatchClauses()) + c.accept(this, v); + if (expr.getFinallyBlock() != null) + expr.getFinallyBlock().accept(this, v); + + expectExpression.pop(); + sb.addAllStatements(statements.pop()); + + pushStatementOrExpr(sb); + return null; + } + + @Override + public Void visitCatchSection(final KtCatchClause n, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.CATCH); + + if (n.getParameterList() != null) { + fields.push(new ArrayList()); + n.getParameterList().accept(this, v); + sb.addAllVariableDeclarations(fields.pop()); + } + + final KtExpression body = n.getCatchBody(); + + if (body instanceof KtBlockExpression) { + for (final KtExpression e : ((KtBlockExpression) body).getStatements()) { + statements.push(new ArrayList()); + expressions.push(new ArrayList()); + + e.accept(this, v); + + for (final Expression ex : expressions.pop()) + sb.addStatements(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(ex) + .build()); + sb.addAllStatements(statements.pop()); + } + } else { + statements.push(new ArrayList()); + expressions.push(new ArrayList()); + + body.accept(this, v); + + for (final Expression ex : expressions.pop()) + sb.addStatements(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(ex) + .build()); + sb.addAllStatements(statements.pop()); + } + + statements.peek().add(sb.build()); + return null; + } + + @Override + public Void visitFinallySection(final KtFinallySection n, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.FINALLY); + + for (final KtExpression e : n.getFinalExpression().getStatements()) { + statements.push(new ArrayList()); + expressions.push(new ArrayList()); + + e.accept(this, v); + + for (final Expression ex : expressions.pop()) + sb.addStatements(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(ex) + .build()); + sb.addAllStatements(statements.pop()); + } + + statements.peek().add(sb.build()); + return null; + } + + @Override + public Void visitThisExpression(final KtThisExpression expr, final Void v) { + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.VARACCESS) + .setVariable(expr.getText()) + .build()); + return null; + } + + @Override + public Void visitSuperExpression(final KtSuperExpression expr, final Void v) { + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.VARACCESS) + .setVariable(expr.getText()) + .build()); + return null; + } + + @Override + public Void visitClassInitializer(final KtClassInitializer n, final Void v) { + final Method.Builder mb = Method.newBuilder(); + + mb.setName(""); + + modifiers.push(new ArrayList()); + if (n.getModifierList() != null) + n.getModifierList().accept(this, v); + mb.addAllModifiers(modifiers.pop()); + + statements.push(new ArrayList()); + expressions.push(new ArrayList()); + expectExpression.push(false); + + n.getBody().accept(this, v); + + expectExpression.pop(); + for (final Expression e : expressions.pop()) + mb.addStatements(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(e) + .build()); + mb.addAllStatements(statements.pop()); + + methods.peek().add(mb.build()); + return null; + } + + @Override + public Void visitTypeConstraint(final KtTypeConstraint n, final Void v) { + // FIXME can remove this when type constraints handled everywhere + System.err.println(n.getClass()); + return null; + } + + @Override + public Void visitBinaryWithTypeRHSExpression(final KtBinaryExpressionWithTypeRHS expr, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + expressions.push(new ArrayList()); + expr.getLeft().accept(this, v); + eb.addAllExpressions(expressions.pop()); + + eb.setNewType(typeFromTypeRef(expr.getRight())); + + switch (expr.getOperationReference().getText()) { + case "as": + eb.setKind(Expression.ExpressionKind.CAST); + break; + case "as?": + default: + eb.setKind(Expression.ExpressionKind.CAST); + eb.setSafe(true); + break; + } + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitTypeProjection(final KtTypeProjection n, final Void v) { + if (n.getTypeReference() != null) + types.peek().add(typeFromTypeRef(n.getTypeReference(), TypeKind.GENERIC)); + else + types.peek().add(Type.newBuilder() + .setName("*") + .setKind(TypeKind.GENERIC) + .build()); + return null; + } + + @Override + public Void visitWhenExpression(final KtWhenExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.SWITCH); + + expressions.push(new ArrayList()); + expectExpression.push(true); + if (expr.getSubjectVariable() != null) + expr.getSubjectVariable().accept(this, v); + else if (expr.getSubjectExpression() != null) + expr.getSubjectExpression().accept(this, v); + expectExpression.pop(); + sb.addAllConditions(expressions.pop()); + + statements.push(new ArrayList()); + expectExpression.push(false); + for (final KtWhenEntry entry : expr.getEntries()) + entry.accept(this, v); + expectExpression.pop(); + sb.addAllStatements(statements.pop()); + + pushStatementOrExpr(sb); + return null; + } + + @Override + public Void visitWhenEntry(final KtWhenEntry n, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + if (n.isElse()) { + sb.setKind(Statement.StatementKind.DEFAULT); + } else { + sb.setKind(Statement.StatementKind.CASE); + + if (n.getConditions().length != 0) { + expressions.push(new ArrayList()); + for (final KtWhenCondition cond : n.getConditions()) + cond.accept(this, v); + sb.addAllExpressions(expressions.pop()); + } + } + + statements.peek().add(sb.build()); + + if (n.getExpression() != null) { + expressions.push(new ArrayList()); + n.getExpression().accept(this, v); + for (final Expression e : expressions.pop()) + statements.peek().add(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(e) + .build()); + } + + return null; + } + + @Override + public Void visitIsExpression(final KtIsExpression expr, final Void v) { + Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.TYPECOMPARE); + + expressions.push(new ArrayList()); + expr.getLeftHandSide().accept(this, v); + eb.addAllExpressions(expressions.pop()); + + eb.setNewType(typeFromTypeRef(expr.getTypeReference())); + + if (expr.isNegated()) { + final Expression isExpr = eb.build(); + + eb = Expression.newBuilder(); + eb.setKind(Expression.ExpressionKind.LOGICAL_NOT); + eb.addExpressions(isExpr); + } + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitWhenConditionIsPattern(final KtWhenConditionIsPattern n, final Void v) { + Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.TYPECOMPARE); + eb.setNewType(typeFromTypeRef(n.getTypeReference())); + + if (n.isNegated()) { + final Expression isExpr = eb.build(); + + eb = Expression.newBuilder(); + eb.setKind(Expression.ExpressionKind.LOGICAL_NOT); + eb.addExpressions(isExpr); + } + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitWhenConditionInRange(final KtWhenConditionInRange n, final Void v) { + Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.IN); + + expressions.push(new ArrayList()); + n.getRangeExpression().accept(this, v); + eb.addAllExpressions(expressions.pop()); + + if (n.isNegated()) { + final Expression expr = eb.build(); + + eb = Expression.newBuilder(); + eb.setKind(Expression.ExpressionKind.LOGICAL_NOT); + eb.addExpressions(expr); + } + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitWhenConditionWithExpression(final KtWhenConditionWithExpression expr, final Void v) { + expr.getExpression().accept(this, v); + return null; + } + + @Override + public Void visitStringTemplateExpression(final KtStringTemplateExpression expr, final Void v) { + final KtStringTemplateEntry[] entries = expr.getEntries(); + + boolean allLiterals = true; + for (int i = 0; i < entries.length; i++) + if (!(entries[i] instanceof KtLiteralStringTemplateEntry)) + allLiterals = false; + + if (allLiterals) { + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.LITERAL) + .setLiteral(expr.getText()) + .build()); + } else { + final StringBuilder sb = new StringBuilder(); + sb.append(expr.getText()); + + expressions.push(new ArrayList()); + for (final KtStringTemplateEntry e : entries) + e.accept(this, v); + final List exprs = expressions.pop(); + + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.TEMPLATE) + // add the whole thing as a single string literal + .setLiteral(sb.toString()) + // then add each individual part + .addAllExpressions(exprs) + .build()); + } + + return null; + } + + @Override + public Void visitStringTemplateEntry(final KtStringTemplateEntry st, final Void v) { + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.TEMPLATE) + .setLiteral("\"" + st.getText() + "\"") + .build()); + return null; + } + + @Override + public Void visitStringTemplateEntryWithExpression(final KtStringTemplateEntryWithExpression st, final Void v) { + final List exprs = new ArrayList(); + + expressions.push(exprs); + st.getExpression().accept(this, v); + expressions.pop(); + + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.TEMPLATE) + .setLiteral("\"" + st.getText() + "\"") + .addAllExpressions(exprs) + .build()); + return null; + } + + @Override + public Void visitBreakExpression(final KtBreakExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.BREAK); + + final String label = expr.getLabelName(); + if (label != null) + sb.addExpressions(Expression.newBuilder() + .setLiteral(label) + .setKind(Expression.ExpressionKind.LABEL) + .build()); + + pushStatementOrExpr(sb); + return null; + } + + @Override + public Void visitContinueExpression(final KtContinueExpression expr, final Void v) { + final Statement.Builder sb = Statement.newBuilder(); + + sb.setKind(Statement.StatementKind.CONTINUE); + + final String label = expr.getLabelName(); + if (label != null) + sb.addExpressions(Expression.newBuilder() + .setLiteral(label) + .setKind(Expression.ExpressionKind.LABEL) + .build()); + + pushStatementOrExpr(sb); + return null; + } + + @Override + public Void visitConstantExpression(final KtConstantExpression expr, final Void v) { + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.LITERAL) + .setLiteral(expr.getText()) + .build()); + return null; + } + + @Override + public Void visitBinaryExpression(final KtBinaryExpression expr, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + switch (expr.getOperationToken().toString()) { + // arithmetic expressions + case "PLUS": + eb.setKind(Expression.ExpressionKind.OP_ADD); + break; + case "MUL": + eb.setKind(Expression.ExpressionKind.OP_MULT); + break; + case "MINUS": + case "SUB": + eb.setKind(Expression.ExpressionKind.OP_SUB); + break; + case "DIV": + eb.setKind(Expression.ExpressionKind.OP_DIV); + break; + case "PERC": + case "MOD": + eb.setKind(Expression.ExpressionKind.OP_MOD); + break; + + // Comparisons + case "LTEQ": + eb.setKind(Expression.ExpressionKind.LTEQ); + break; + case "GTEQ": + eb.setKind(Expression.ExpressionKind.GTEQ); + break; + case "GT": + eb.setKind(Expression.ExpressionKind.GT); + break; + case "LT": + eb.setKind(Expression.ExpressionKind.LT); + break; + case "EQEQ": + eb.setKind(Expression.ExpressionKind.EQ); + break; + case "EQEQEQ": + eb.setKind(Expression.ExpressionKind.SHEQ); + break; + case "EXCLEQEQEQ": + eb.setKind(Expression.ExpressionKind.SHNEQ); + break; + case "NOT_IN": + eb.setKind(Expression.ExpressionKind.NOT_IN); + break; + case "ELVIS": + eb.setKind(Expression.ExpressionKind.OP_ELVIS); + break; + case "EXCLEQ": + eb.setKind(Expression.ExpressionKind.NEQ); + break; + + // Logical operators + case "ANDAND": + eb.setKind(Expression.ExpressionKind.LOGICAL_AND); + break; + case "OROR": + eb.setKind(Expression.ExpressionKind.LOGICAL_OR); + break; + + // Sets + case "in": + eb.setKind(Expression.ExpressionKind.IN); + break; + case "RANGE": + eb.setKind(Expression.ExpressionKind.ARRAY_COMPREHENSION); + break; + + // Assignment & assignment-like + case "EQ": + eb.setKind(Expression.ExpressionKind.ASSIGN); + break; + case "PLUSEQ": + eb.setKind(Expression.ExpressionKind.ASSIGN_ADD); + break; + case "MINUSEQ": + eb.setKind(Expression.ExpressionKind.ASSIGN_SUB); + break; + case "MULTEQ": + eb.setKind(Expression.ExpressionKind.ASSIGN_MULT); + break; + case "DIVEQ": + eb.setKind(Expression.ExpressionKind.ASSIGN_DIV); + break; + case "PERCEQ": + eb.setKind(Expression.ExpressionKind.ASSIGN_MOD); + break; + + // When we use an identifier for the operation + case "IDENTIFIER": + switch (expr.getOperationReference().getText()) { + case "and": + eb.setKind(Expression.ExpressionKind.BIT_AND); + break; + case "or": + eb.setKind(Expression.ExpressionKind.BIT_OR); + break; + case "shl": + eb.setKind(Expression.ExpressionKind.BIT_LSHIFT); + break; + case "shr": + eb.setKind(Expression.ExpressionKind.BIT_RSHIFT); + break; + case "xor": + eb.setKind(Expression.ExpressionKind.BIT_XOR); + break; + case "ushr": + eb.setKind(Expression.ExpressionKind.BIT_UNSIGNEDRSHIFT); + break; + case "downTo": + eb.setKind(Expression.ExpressionKind.ARRAY_COMPREHENSION); + eb.setLiteral("downTo"); + break; + case "until": + eb.setKind(Expression.ExpressionKind.ARRAY_COMPREHENSION); + eb.setLiteral("until"); + break; + case "step": + expressions.push(new ArrayList()); + expectExpression.push(true); + expr.getLeft().accept(this, v); + final Expression.Builder eb2 = Expression.newBuilder(expressions.pop().get(0)); + expressions.push(new ArrayList()); + expr.getRight().accept(this, v); + eb2.addExpressions(expressions.pop().get(0)); + expectExpression.pop(); + expressions.peek().add(eb2.build()); + return null; + default: + eb.setKind(Expression.ExpressionKind.OTHER); + eb.setLiteral(expr.getOperationReference().getText()); + // System.err.println("===> UNKNOWN BINARY OPERATOR ID: " + expr.getOperationReference().getText()); + break; + } + break; + + default: + eb.setKind(Expression.ExpressionKind.OTHER); + eb.setLiteral(expr.getOperationToken().toString()); + System.err.println("===> UNKNOWN BINARY OPERATOR: " + expr.getOperationToken().toString()); + break; + } + + expectExpression.push(true); + expressions.push(new ArrayList()); + expr.getLeft().accept(this, v); + expr.getRight().accept(this, v); + eb.addAllExpressions(expressions.pop()); + expectExpression.pop(); + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitParenthesizedExpression(final KtParenthesizedExpression expr, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.PAREN); + + expressions.push(new ArrayList()); + expr.acceptChildren(this, v); + eb.addAllExpressions(expressions.pop()); + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public Void visitPropertyAccessor(final KtPropertyAccessor acc, final Void v) { + final Method.Builder mb = Method.newBuilder(); + final KtProperty prop = acc.getProperty(); + + modifiers.push(new ArrayList()); + if (acc.getModifierList() != null) + acc.getModifierList().accept(this, v); + mb.addAllModifiers(modifiers.pop()); + + final String propName; + if (prop.getReceiverTypeReference() != null) + propName = prop.getReceiverTypeReference().getText() + "." + prop.getNameIdentifier().getText(); + else + propName = prop.getNameIdentifier().getText(); + mb.setName(propName + "." + (acc.isGetter() ? "" : "")); + + fields.push(new ArrayList()); + expectExpression.push(false); + for (final KtParameter p : acc.getValueParameters()) + p.accept(this, v); + expectExpression.pop(); + mb.addAllArguments(fields.pop()); + + if (acc.getReturnTypeReference() != null) { + mb.setReturnType(typeFromTypeRef(acc.getReturnTypeReference())); + } else { + if (acc.isSetter()) { + mb.setReturnType(Type.newBuilder() + .setName("Unit") + .setKind(TypeKind.OTHER) + .build()); + } else { + final KtTypeReference typeRef = prop.getTypeReference(); + if (typeRef != null) + mb.setReturnType(typeFromTypeRef(typeRef)); + } + } + + if (acc.getBodyBlockExpression() != null) { + expectExpression.push(false); + statements.push(new ArrayList()); + acc.getBodyBlockExpression().accept(this, v); + mb.addAllStatements(statements.pop()); + expectExpression.pop(); + } else if (acc.getBodyExpression() != null) { + expectExpression.push(true); + expressions.push(new ArrayList()); + acc.getBodyExpression().accept(this, v); + mb.setExpression(expressions.pop().get(0)); + expectExpression.pop(); + } + + methods.peek().add(mb.build()); + return null; + } + + @Override + public Void visitProperty(final KtProperty prop, final Void v) { + final Variable.Builder vb = Variable.newBuilder(); + + expectExpression.push(true); + + if (prop.getReceiverTypeReference() != null) + vb.setName(prop.getReceiverTypeReference().getText() + "." + prop.getName()); + else + vb.setName(prop.getName()); + + if (prop.getValOrVarKeyword() == null) + vb.addModifiers(Modifier.newBuilder() + .setKind(Modifier.ModifierKind.IMPLICIT) + .build()); + + final KtTypeReference typeRef = prop.getTypeReference(); + final KtPropertyDelegate propDelegate = prop.getDelegate(); + if (propDelegate != null) { + final Type.Builder tb = Type.newBuilder(); + + tb.setKind(TypeKind.DELEGATED); + if (typeRef != null) + tb.setName(typeRef.getText()); + + if (propDelegate.getExpression() != null) { + expressions.push(new ArrayList()); + propDelegate.getExpression().accept(this, v); + tb.setDelegate(expressions.pop().get(0)); + } + + vb.setVariableType(tb.build()); + } else if (typeRef != null) { + vb.setVariableType(typeFromTypeRef(typeRef)); + } + + modifiers.push(new ArrayList()); + if (!prop.isVar()) + modifiers.peek().add(Modifier.newBuilder() + .setKind(Modifier.ModifierKind.FINAL) + .build()); + if (prop.getModifierList() != null) + prop.getModifierList().accept(this, v); + vb.addAllModifiers(modifiers.pop()); + + if (prop.hasInitializer()) { + if (prop.getReceiverTypeReference() != null) { + throw new RuntimeException("visted extension property with initializer"); + } + + expressions.push(new ArrayList()); + expectExpression.push(true); + + prop.getInitializer().accept(this, v); + + expectExpression.pop(); + vb.setInitializer(expressions.pop().get(0)); + } + + if (prop.getGetter() != null) + prop.getGetter().accept(this, v); + if (prop.getSetter() != null) + prop.getSetter().accept(this, v); + + // TODO type constraints + if (prop.getTypeConstraintList() != null) + prop.getTypeConstraintList().accept(this, v); + + expectExpression.pop(); + + if (expectExpression.peek()) + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.VARDECL) + .addVariableDecls(vb.build()) + .build()); + else if (prop.getReceiverTypeReference() == null) + fields.peek().add(vb.build()); + + return null; + } + + @Override + public Void visitClass(final KtClass klass, final Void v) { + final Declaration.Builder db = Declaration.newBuilder(); + + db.setName(klass.getNameAsSafeName().asString()); + + if (klass.isInterface()) + db.setKind(TypeKind.INTERFACE); + else if (klass.isEnum()) + db.setKind(TypeKind.ENUM); + else if (klass.isData()) + db.setKind(TypeKind.IMMUTABLE); + else if (klass.isAnnotation()) + db.setKind(TypeKind.ANNOTATION); + else + db.setKind(TypeKind.CLASS); + + expectExpression.push(false); + for (final KtTypeParameter p : klass.getTypeParameters()) + db.addGenericParameters(buildGenericParam(p, klass.getTypeConstraints())); + + if (klass.getSuperTypeList() != null) { + types.push(new ArrayList()); + klass.getSuperTypeList().accept(this, v); + db.addAllParents(types.pop()); + } + + if (klass.getModifierList() != null) { + modifiers.push(new ArrayList()); + klass.getModifierList().accept(this, v); + db.addAllModifiers(modifiers.pop()); + } + + fields.push(new ArrayList()); + methods.push(new ArrayList()); + declarations.push(new ArrayList()); + + if (klass.getPrimaryConstructor() != null) + klass.getPrimaryConstructor().accept(this, v); + + if (klass.getBody() != null) + klass.getBody().accept(this, v); + + db.addAllNestedDeclarations(declarations.pop()); + db.addAllMethods(methods.pop()); + db.addAllFields(fields.pop()); + + expectExpression.pop(); + + if (expectExpression.peek()) { + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.OTHER) + .setAnonDeclaration(db.build()) + .build()); + } else { + declarations.peek().add(db.build()); + } + + superClassInitExprs.clear(); + return null; + } + + private > void visitConstructor(final KtConstructor constructor, final boolean isPrimary) { + final Method.Builder mb = Method.newBuilder(); + + mb.setName(""); + + modifiers.push(new ArrayList()); + if (isPrimary) + modifiers.peek().add(Modifier.newBuilder() + .setKind(Modifier.ModifierKind.OTHER) + .setOther("primary") + .build()); + if (constructor.getModifierList() != null) + constructor.getModifierList().accept(this, null); + mb.addAllModifiers(modifiers.pop()); + + statements.push(new ArrayList()); + + if (isPrimary) { + final List stmts = new ArrayList(); + for (final Expression expr : superClassInitExprs) + stmts.add(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(expr) + .build()); + if (stmts.size() > 0) + statements.peek().add(Statement.newBuilder() + .setKind(Statement.StatementKind.BLOCK) + .addAllStatements(stmts) + .build()); + } else { + if (!((KtSecondaryConstructor) constructor).hasImplicitDelegationCall()) { + expressions.push(new ArrayList()); + ((KtSecondaryConstructor) constructor).getDelegationCall().accept(this, null); + statements.peek().add(Statement.newBuilder() + .setKind(Statement.StatementKind.EXPRESSION) + .addExpressions(Expression.newBuilder() + .setKind(Expression.ExpressionKind.METHODCALL) + .setMethod(((KtSecondaryConstructor) constructor) + .getDelegationCall() + .getCalleeExpression() + .isThis() ? "this" : "super") + .addAllExpressions(expressions.pop()) + .build()) + .build()); + } + } + + if (constructor.getBodyExpression() != null) + constructor.getBodyExpression().accept(this, null); + + mb.addAllStatements(statements.pop()); + + fields.push(new ArrayList()); + if (constructor.getValueParameterList() != null) + constructor.getValueParameterList().accept(this, null); + mb.addAllArguments(fields.pop()); + + if (isPrimary && constructor.getValueParameterList() != null) + for (final KtParameter p : constructor.getValueParameterList().getParameters()) + if (p.hasValOrVar()) + p.accept(this, null); + + methods.peek().add(mb.build()); + } + + @Override + public Void visitPrimaryConstructor(final KtPrimaryConstructor constructor, final Void v) { + visitConstructor(constructor, true); + return null; + } + + @Override + public Void visitSecondaryConstructor(final KtSecondaryConstructor constructor, final Void v) { + visitConstructor(constructor, false); + return null; + } + + @Override + public Void visitNamedFunction(final KtNamedFunction function, final Void v) { + final Method.Builder mb = Method.newBuilder(); + + mb.setName(function.getName() != null ? function.getName() : ""); + + if (function.getModifierList() != null) { + modifiers.push(new ArrayList()); + function.getModifierList().accept(this, v); + mb.addAllModifiers(modifiers.pop()); + } + + if (function.hasDeclaredReturnType()) + mb.setReturnType(typeFromTypeRef(function.getTypeReference())); + + for (final KtTypeParameter p : function.getTypeParameters()) + mb.addGenericParameters(buildGenericParam(p, function.getTypeConstraints())); + + if (function.getReceiverTypeReference() != null) + mb.setReceiverType(typeFromTypeRef(function.getReceiverTypeReference())); + + expectExpression.push(false); + fields.push(new ArrayList()); + for (final KtParameter p : function.getValueParameters()) + p.accept(this, v); + mb.addAllArguments(fields.pop()); + expectExpression.pop(); + + if (function.getBodyBlockExpression() != null) { + expectExpression.push(false); + statements.push(new ArrayList()); + function.getBodyBlockExpression().accept(this, v); + mb.addAllStatements(statements.pop()); + expectExpression.pop(); + } else if (function.getBodyExpression() != null) { + expectExpression.push(true); + expressions.push(new ArrayList()); + function.getBodyExpression().accept(this, v); + mb.setExpression(expressions.pop().get(0)); + expectExpression.pop(); + } + + if (expectExpression.peek()) + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.METHODDECL) + .addMethods(mb.build()) + .build()); + else + methods.peek().add(mb.build()); + return null; + } + + @Override + public Void visitParameter(final KtParameter param, final Void v) { + if (param.getDestructuringDeclaration() != null) { + param.getDestructuringDeclaration().accept(this, v); + return null; + } + + final Variable.Builder vb = Variable.newBuilder(); + + expectExpression.push(true); + + if (param.getName() != null) + vb.setName(param.getName()); + + if (param.getTypeReference() != null) + vb.setVariableType(typeFromTypeRef(param.getTypeReference())); + + if (!param.hasValOrVar()) + vb.addModifiers(Modifier.newBuilder() + .setKind(Modifier.ModifierKind.IMPLICIT) + .build()); + + if (!param.hasValOrVar() || !param.isMutable()) + vb.addModifiers(Modifier.newBuilder() + .setKind(Modifier.ModifierKind.FINAL) + .build()); + + if (param.getModifierList() != null) { + modifiers.push(new ArrayList()); + param.getModifierList().accept(this, v); + vb.addAllModifiers(modifiers.pop()); + } + + if (param.hasDefaultValue()) { + final List exprs = new ArrayList(); + expressions.push(exprs); + expectExpression.push(true); + param.getDefaultValue().accept(this, v); + expectExpression.pop(); + vb.setInitializer(exprs.get(0)); + expressions.pop(); + } + + expectExpression.pop(); + + if (expectExpression.peek()) + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.VARDECL) + .addVariableDecls(vb.build()) + .build()); + else + fields.peek().add(vb.build()); + return null; + } + + @Override + public Void visitCallExpression(final KtCallExpression call, final Void v) { + final Expression.Builder eb = Expression.newBuilder(); + + eb.setKind(Expression.ExpressionKind.METHODCALL); + + if ((call.getParent() instanceof KtCallableReferenceExpression) && (call.getValueArgumentList() == null) && (call.getLambdaArguments().size() == 0)) { + eb.setKind(Expression.ExpressionKind.VARACCESS); + eb.setVariable(call.getCalleeExpression().getText()); + } else if (!(call.getCalleeExpression() instanceof KtNameReferenceExpression)) { + eb.setMethod(""); + expressions.push(new ArrayList()); + call.getCalleeExpression().accept(this, v); + eb.addAllExpressions(expressions.pop()); + } else { + eb.setMethod(call.getCalleeExpression().getText()); + } + + if (call.getValueArgumentList() != null) { + expressions.push(new ArrayList()); + call.getValueArgumentList().accept(this, v); + eb.addAllMethodArgs(expressions.pop()); + } + + if (call.getLambdaArguments() != null) { + expressions.push(new ArrayList()); + for (final KtLambdaArgument arg : call.getLambdaArguments()) + arg.accept(this, v); + eb.addAllMethodArgs(expressions.pop()); + } + + if (call.getTypeArgumentList() != null) { + types.push(new ArrayList()); + call.getTypeArgumentList().accept(this, v); + eb.addAllGenericParameters(types.pop()); + } + + expressions.peek().add(eb.build()); + return null; + } + + @Override + public void visitWhiteSpace(final PsiWhiteSpace space) { + // ignore + } + + // Utility methods + private Type typeFromTypeRef(final KtTypeReference type) { + return typeFromTypeRef(type, TypeKind.OTHER); + } + + private Type typeFromTypeRef(final KtTypeReference type, TypeKind kind) { + final Type.Builder tb = Type.newBuilder(); + tb.setName(type.getText()); + if (type.getText().equals("dynamic") && (kind == TypeKind.OTHER)) + tb.setKind(TypeKind.DYNAMIC); + else + tb.setKind(kind); + return tb.build(); + } + + private void pushStatementOrExpr(final Statement.Builder sb) { + if (expectExpression.peek()) { + final Expression.Builder eb = Expression.newBuilder(); + eb.setKind(Expression.ExpressionKind.STATEMENT); + eb.addStatements(sb.build()); + expressions.peek().add(eb.build()); + } else { + statements.peek().add(sb.build()); + } + } + + private void pushEmpty() { + expressions.peek().add(Expression.newBuilder() + .setKind(Expression.ExpressionKind.EMPTY) + .build()); + } + + private Type buildGenericParam(final KtTypeParameter p, final List tcList) { + final StringBuilder sb = new StringBuilder(); + if (p.getModifierList() != null) + sb.append(p.getModifierList().getText().replaceAll("\\\\n", "").replaceAll("\\s+", " ") + " "); + + sb.append(p.getName()); + + boolean first = true; + + if (p.getExtendsBound() != null) { + sb.append(" : "); + sb.append(p.getExtendsBound().getText()); + first = false; + } + + if (tcList != null) + for (final KtTypeConstraint tc : tcList) + if (tc.getSubjectTypeParameterName().getReferencedName() == p.getName()) { + if (first) { + sb.append(" : "); + first = false; + } else { + sb.append(" & "); + } + sb.append(tc.getBoundTypeReference().getText()); + } + + return Type.newBuilder() + .setName(sb.toString()) + .setKind(TypeKind.GENERIC) + .build(); + } +} diff --git a/src/java/boa/functions/BoaAstIntrinsics.java b/src/java/boa/functions/BoaAstIntrinsics.java index da988012b..badbf1a91 100644 --- a/src/java/boa/functions/BoaAstIntrinsics.java +++ b/src/java/boa/functions/BoaAstIntrinsics.java @@ -36,6 +36,7 @@ import boa.datagen.DefaultProperties; import boa.functions.langmode.JavaLangMode; +import boa.functions.langmode.KotlinLangMode; import boa.functions.langmode.LangMode; import boa.types.Ast.ASTRoot; import boa.types.Ast.CommentsRoot; @@ -652,6 +653,7 @@ public static String debug(final String s) { } private static final LangMode javaLang = new JavaLangMode(); + private static final LangMode kotlinLang = new KotlinLangMode(); private static ChangedFile.FileKind curLang = ChangedFile.FileKind.SOURCE_JAVA_JLS8; private static LangMode lang = javaLang; @@ -668,6 +670,15 @@ public static void setlang(final ChangedFile.FileKind l) { curLang = l; switch (curLang) { + case SOURCE_KOTLIN_1_5: + case SOURCE_KOTLIN_1_4: + case SOURCE_KOTLIN_1_3: + case SOURCE_KOTLIN_1_2: + case SOURCE_KOTLIN_1_1: + case SOURCE_KOTLIN_1_0: + lang = kotlinLang; + break; + default: lang = javaLang; break; diff --git a/src/java/boa/functions/langmode/JavaLangMode.java b/src/java/boa/functions/langmode/JavaLangMode.java index 368a17d3e..f94bf1dd1 100644 --- a/src/java/boa/functions/langmode/JavaLangMode.java +++ b/src/java/boa/functions/langmode/JavaLangMode.java @@ -764,7 +764,7 @@ public String prettyprint(final Expression e) { return s; case ANNOTATION: - return prettyprint(e.getAnnotation()); + return prettyprint(e.getModifiersList()); case VARDECL: s += prettyprint(e.getVariableDecls(0).getModifiersList()); diff --git a/src/java/boa/functions/langmode/KotlinLangMode.java b/src/java/boa/functions/langmode/KotlinLangMode.java new file mode 100644 index 000000000..ebe9aa050 --- /dev/null +++ b/src/java/boa/functions/langmode/KotlinLangMode.java @@ -0,0 +1,1023 @@ +/* + * Copyright 2021, Robert Dyer + * and University of Nebraska Board of Regents + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.functions.langmode; + +import java.util.List; +import java.util.ArrayList; + +import com.intellij.core.CoreFileTypeRegistry; +import com.intellij.lang.LanguageParserDefinitions; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.fileTypes.FileTypeRegistry; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiManager; +import com.intellij.testFramework.LightVirtualFile; +import org.jetbrains.kotlin.idea.KotlinLanguage; +import org.jetbrains.kotlin.idea.KotlinFileType; +import org.jetbrains.kotlin.parsing.KotlinParserDefinition; +import org.jetbrains.kotlin.psi.KtFile; +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreProjectEnvironment; +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreApplicationEnvironment; + +import boa.datagen.util.KotlinErrorCheckVisitor; +import boa.datagen.util.KotlinVisitor; +import boa.types.Ast.ASTRoot; +import boa.types.Ast.Declaration; +import boa.types.Ast.Expression; +import boa.types.Ast.Method; +import boa.types.Ast.Modifier; +import boa.types.Ast.Namespace; +import boa.types.Ast.Statement; +import boa.types.Ast.Type; +import boa.types.Ast.TypeKind; +import boa.types.Ast.Variable; + +/** + * Boa functions for working with Kotlin ASTs. + * + * @author rdyer + */ +public class KotlinLangMode implements LangMode { + public String type_name(final String s) { + // first, normalize the string + final String t = s.replaceAll("<\\s+", "<") + .replaceAll(",\\s+", ", ") + .replaceAll("\\s*>\\s*", ">") + .replaceAll("\\s*&\\s*", " & "); + + if (!t.contains(".")) + return t; + + /* + * Remove qualifiers from anywhere in the string... + * + * SomeType => SomeType + * foo.SomeType => SomeType + * foo.bar.SomeType => SomeType + * SomeType => SomeType + * SomeType => SomeType + * SomeType => SomeType + * SomeType => SomeType + * foo.bar.SomeType> => SomeType> + * SomeType&foo.Bar => SomeType&Bar + * foo.bar => foo.bar + */ + return t.replaceAll("[^\\s,<>&]+\\.([^\\s\\[.,><&]+)", "$1"); + } + + /////////////////////////////// + // Literal testing functions */ + /////////////////////////////// + + /** + * Returns true if the expression e is of kind + * LITERAL and is an integer literal. + * + *

The test is a simplified grammar, based on the one from: + * https://github.com/Kotlin/kotlin-spec/blob/648afef3b9a7fccec7fdaa4aabde6d114bcf9d69/grammar/src/main/antlr/KotlinLexer.g4 + * + *

IntegerLiteral + * ([1..9] [0..9_]*)? [0..9] [uU]? [lL]? + * + *

HexLiteral + * '0' [xX] [0-9a-fA-F] ([0-9a-fA-F_]* [0-9a-fA-F])? [uU]? [lL]? + * + *

BinLiteral + * '0' [bB] [01] ([01_]* [01])? [uU]? [lL]? + * + *

If any of these match, it returns true. Otherwise it + * returns false. + * + * @param e the expression to test + * @return true if the expression is an integer literal, otherwise false + */ + public boolean isIntLit(final Expression e) throws Exception { + if (e.getKind() != Expression.ExpressionKind.LITERAL) return false; + if (!e.hasLiteral()) return false; + final String lit = e.getLiteral(); + + if (lit.matches("^([1..9][0..9_]*)?[0..9][uU]?[lL]?$")) return true; + if (lit.matches("^0[xX][0-9a-fA-F]([0-9a-fA-F_]*[0-9a-fA-F])?[uU]?[lL]?$")) return true; + return lit.matches("^0[bB][01]([01_]*[01])?[uU]?[lL]?$"); + } + + /** + * Returns true if the expression e is of kind + * LITERAL and is a float literal. + * + *

The test is a simplified grammar, based on the one from: + * https://github.com/Kotlin/kotlin-spec/blob/648afef3b9a7fccec7fdaa4aabde6d114bcf9d69/grammar/src/main/antlr/KotlinLexer.g4 + * + *

FloatLiteral + * ([0..9] ([0..9_]* [0..9])?)? '.' [0..9] ([0..9_]* [0..9])? ([eE] [+-]? [0..9] ([0..9_]* [0..9])?)? [fF] + * [0..9] ([0..9_]* [0..9])? [eE] [+-]? [0..9] ([0..9_]* [0..9])? [fF] + * [0..9] ([0..9_]* [0..9])? [fF] + * + *

DoubleLiteral + * ([0..9] ([0..9_]* [0..9])?)? '.' [0..9] ([0..9_]* [0..9])? ([eE] [+-]? [0..9] ([0..9_]* [0..9])?)? + * [0..9] ([0..9_]* [0..9])? [eE] [+-]? [0..9] ([0..9_]* [0..9])? + * + *

If any of these match, it returns true. Otherwise it + * returns false. + * + * @param e the expression to test + * @return true if the expression is a char literal, otherwise false + */ + public boolean isFloatLit(final Expression e) throws Exception { + if (e.getKind() != Expression.ExpressionKind.LITERAL) return false; + if (!e.hasLiteral()) return false; + final String lit = e.getLiteral(); + + if (lit.matches("^([0..9]([0..9_]*[0..9])?)?\\.[0..9]([0..9_]*[0..9])?([eE][+-]?[0..9]([0..9_]*[0..9])?)?[fF]$")) return true; + if (lit.matches("^[0..9]([0..9_]*[0..9])?[eE][+-]?[0..9]([0..9_]*[0..9])?[fF]$")) return true; + if (lit.matches("^[0..9]([0..9_]*[0..9])?[fF]$")) return true; + + if (lit.matches("^([0..9]([0..9_]*[0..9])?)?\\.[0..9]([0..9_]*[0..9])?([eE][+-]?[0..9]([0..9_]*[0..9])?)?$")) return true; + return lit.matches("^[0..9]([0..9_]*[0..9])?[eE][+-]?[0..9]([0..9_]*[0..9])?$"); + } + + public boolean isCharLit(final Expression e) throws Exception { + if (e.getKind() != Expression.ExpressionKind.LITERAL) return false; + if (!e.hasLiteral()) return false; + return e.getLiteral().startsWith("'"); + } + + public boolean isStringLit(final Expression e) throws Exception { + if (e.getKind() != Expression.ExpressionKind.LITERAL) return false; + if (!e.hasLiteral()) return false; + return e.getLiteral().startsWith("\""); + } + + public boolean isTypeLit(final Expression e) throws Exception { + return false; + } + + public boolean isBoolLit(final Expression e) throws Exception { + if (e.getKind() != Expression.ExpressionKind.LITERAL) return false; + if (!e.hasLiteral()) return false; + final String lit = e.getLiteral(); + + return lit.equals("true") || lit.equals("false"); + } + + public boolean isNullLit(final Expression e) throws Exception { + if (e.getKind() != Expression.ExpressionKind.LITERAL) return false; + if (!e.hasLiteral()) return false; + return e.getLiteral().equals("null"); + } + + public boolean isLiteral(final Expression e, final String lit) throws Exception { + return e.getKind() == Expression.ExpressionKind.LITERAL && e.hasLiteral() && e.getLiteral().equals(lit); + } + + + int indent = 0; + private String indent() { + String s = ""; + for (int i = 0; i < indent; i++) + s += " "; + return s; + } + + public String prettyprint(final ASTRoot r) { + if (r == null) return ""; + + String s = ""; + + for (final Namespace n : r.getNamespacesList()) + s += prettyprint(n); + + return s; + } + + public String prettyprint(final Namespace n) { + if (n == null) return ""; + + String s = ""; + + for (final Modifier m : n.getModifiersList()) + s += prettyprint(m) + "\n"; + + if (n.getName().length() > 0) + s += indent() + "package " + n.getName() + "\n\n"; + + for (final String i : n.getImportsList()) + s += indent() + "import " + i + "\n"; + if (n.getImportsList().size() > 0) + s += "\n"; + + for (final Variable v : n.getVariablesList()) + s += prettyprint(v) + "\n"; + + for (final Declaration d : n.getDeclarationsList()) + s += prettyprint(d); + + for (final Method m : n.getMethodsList()) + s += prettyprint(m); + + for (final Statement st : n.getStatementsList()) + s += prettyprint(st); + + for (final Expression e : n.getExpressionsList()) + s += prettyprint(e); + + return s; + } + + public String prettyprint(final Declaration d) { + // FIXME convert to Kotlin + if (d == null) return ""; + + String s = indent() + prettyprint(d.getModifiersList()); + + switch (d.getKind()) { + case INTERFACE: + s += "interface " + d.getName(); + s += prettyprintClass(d); + break; + case ANONYMOUS: + s += prettyprintDeclarationBody(d); + break; + default: + case CLASS: + if (d.getKind() == TypeKind.IMMUTABLE) + s += "data "; + if (d.getKind() == TypeKind.ENUM) + s += "enum "; + s += "class " + d.getName(); + s += prettyprintClass(d); + break; + } + + return s; + } + + public String prettyprintClass(final Declaration klass) { + String s = ""; + + Method primaryMethod = null; + + final List knownMethods = new ArrayList(); + final List knownFields = new ArrayList(); + + for (int i = 0 ; i < klass.getMethodsCount() ; i++) { + final Method m = klass.getMethods(i); + boolean isPrimary = false; + for (int j = 0 ; j < m.getModifiersCount() ; j++) { + final Modifier mod = m.getModifiers(j); + if ((mod.getKind() == Modifier.ModifierKind.OTHER) && mod.getOther().equals("primary")) { + isPrimary = true; + break; + } + } + if (isPrimary) primaryMethod = m; + else knownMethods.add(m); + } + + if(primaryMethod != null) { + for (int i = 0 ; i < klass.getFieldsCount() ; i++) { + final Variable v = klass.getFields(i); + boolean isInPrimary = false; + for (int j = 0 ; j < primaryMethod.getArgumentsCount() ; j ++) { + final Variable vv = primaryMethod.getArguments(j); + if (v.getName().equals(vv.getName())) { + isInPrimary = true; + break; + } + } + if (!isInPrimary) knownFields.add(v); + } + } else { + knownFields.addAll(klass.getFieldsList()); + } + + if (primaryMethod != null) { + s += "("; + for (int i = 0 ; i < primaryMethod.getArgumentsCount(); i++) { + if (i > 0) s += ", "; + s += prettyprint(primaryMethod.getArguments(i)); + } + s += ")"; + } + + if (klass.getGenericParametersCount() > 0) { + s += "<"; + for (int i = 0; i < klass.getGenericParametersCount(); i++) { + if (i != 0) s += ", "; + s += prettyprint(klass.getGenericParameters(i)); + } + s += ">"; + } + if (klass.getParentsCount() > 0) { + s += " : "; + List statementsToSearch = null; + if (primaryMethod != null) { + if (primaryMethod.getStatementsCount() > 0) { + if (primaryMethod.getStatementsList().get(0).getKind() == Statement.StatementKind.BLOCK) + statementsToSearch = primaryMethod.getStatementsList().get(0).getStatementsList(); + else + statementsToSearch = primaryMethod.getStatementsList(); + } + } + for (int i = 0; i < klass.getParentsCount(); i++) { + if (i > 0) s += ", "; + s += prettyprint(klass.getParents(i)); + if (statementsToSearch != null) { + for (final Statement st : statementsToSearch) { + if ((st.getKind() == Statement.StatementKind.EXPRESSION) + && (st.getExpressionsList().get(0).getKind() == Expression.ExpressionKind.METHODCALL)) { + final Expression expr = st.getExpressionsList().get(0); + if (expr.getMethod().equals(klass.getParents(i).getName())) { + s += "("; + for (int j = 0 ; j < expr.getMethodArgsCount() ; j++) { + if (j > 0) s += ", "; + s += prettyprint(expr.getMethodArgs(j)); + } + s += ")"; + break; + } + } + } + } + } + } + if ((klass.getFieldsCount() > 0) || (klass.getMethodsList().size() > 0) || (klass.getNestedDeclarationsList().size() > 0)) { + s += " {\n"; + indent++; + + for (final Variable field : knownFields) { + s += indent() + prettyprint(field) + "\n"; + } + + for (final Method method : knownMethods) { + s += prettyprint(method) + "\n"; + } + + for (final Declaration decl : klass.getNestedDeclarationsList()) { + s += indent() + prettyprint(decl) + "\n"; + } + + s += "}\n"; + indent--; + } + + return s; + } + + public String prettyprintDeclarationBody(final Declaration d) { + String s = " {\n"; + indent++; + for (int i = 0; i < d.getFieldsCount(); i++) { + s += indent() + prettyprint(d.getFieldsList().get(i)); + s += (!d.getFieldsList().get(i).hasVariableType() + && i < d.getFieldsCount() - 1 + && !d.getFieldsList().get(i + 1).hasVariableType()) ? ",\n" : "\n"; + } + for (final Method m : d.getMethodsList()) + s += m.getName().equals("") ? prettyprint(m).replace(" ", d.getName()) : prettyprint(m); + for (final Declaration d2 : d.getNestedDeclarationsList()) + s += prettyprint(d2); + + indent--; + + s += indent() + "}\n"; + + return s; + } + + public String prettyprint(final Type t) { + // FIXME convert to Kotlin + if (t == null) return ""; + + String s = t.getName(); + + if (t.getKind() == TypeKind.DELEGATED) { + s += " by " + prettyprint(t.getDelegate()); + } + return s; + } + + public String prettyprint(final Method m) { + // FIXME convert to Kotlin + if (m == null) return ""; + String s = indent() + prettyprint(m.getModifiersList()); + + if (m.getName().equals("")) + s += "constructor"; + else if (m.getName().equals("")) + s += "init "; + else + s += "fun "; + + if (m.getGenericParametersCount() > 0) { + s += "<"; + for (int i = 0; i < m.getGenericParametersCount(); i++) { + if (i > 0) + s += ", "; + s += prettyprint(m.getGenericParameters(i)); + } + s += "> "; + } + + if (!m.getName().equals("") && !m.getName().equals("")) + s += m.getName(); + + if (!m.getName().equals("")) { + s += "("; + for (int i = 0; i < m.getArgumentsCount(); i++) { + if (i > 0) + s += ", "; + s += prettyprint(m.getArguments(i)); + } + s += ")"; + } + + if (!m.getReturnType().getName().equals("")) + s += " : " + prettyprint(m.getReturnType()); + + if (m.getExceptionTypesCount() > 0) { + s += " throws"; + for (int i = 0; i < m.getExceptionTypesCount(); i++) + s += " " + prettyprint(m.getExceptionTypes(i)); + } + + if (m.hasExpression()) { + s += " = " + prettyprint(m.getExpression()); + } else { + s += "\n"; + for (int i = 0; i < m.getStatementsCount(); i++) + s += indent() + prettyprint(m.getStatements(i)) + "\n"; + } + + return s; + } + + public String prettyprint(final Variable v) { + // FIXME convert to Kotlin + if (v == null) return ""; + boolean hasVal = false; + boolean isImplicit = false; + + final List mods = v.getModifiersList(); + final List newMods = new ArrayList(); + + for (Modifier mod : mods) { + if (mod.getKind() == Modifier.ModifierKind.FINAL) + hasVal = true; + else if (mod.getKind() == Modifier.ModifierKind.IMPLICIT) + isImplicit = true; + else + newMods.add(mod); + } + + String s = ""; + if (newMods.size() > 0) + s += prettyprint(newMods); + + if (!isImplicit) + s += hasVal ? "val " : "var "; + + s += v.getName(); + + if (v.hasVariableType()) + s += ": " + prettyprint(v.getVariableType()); + + if (v.getExpressionsCount() != 0) + s += "("+ prettyprint(v.getExpressions(0)) +")"; + + if (v.hasInitializer()) + s += " = " + prettyprint(v.getInitializer()); + + return s; + } + + private String prettyprint(final List mods) { + String s = ""; + + for (final Modifier m : mods) + s += prettyprint(m) + " "; + + return s; + } + + public String prettyprint(final Statement stmt) { + // FIXME convert to Kotlin + if (stmt == null) return ""; + + String s = ""; + + switch (stmt.getKind()) { + case EMPTY: + return ";"; + + case BLOCK: + s += "{\n"; + indent++; + for (int i = 0; i < stmt.getStatementsCount(); i++) + s += indent() + prettyprint(stmt.getStatements(i)) + "\n"; + indent--; + s += indent() + "}"; + return s; + + case RETURN: + s += "return"; + if (stmt.getExpressionsCount() > 1) + s += "@" + prettyprint(stmt.getExpressions(0)) + " " + prettyprint(stmt.getExpressions(1)); + else if (stmt.getExpressionsCount() > 0) + s += " " + prettyprint(stmt.getExpressions(0)); + return s; + + case BREAK: + s += "break"; + if (stmt.getExpressionsCount() > 0) + s += "@" + prettyprint(stmt.getExpressions(0)); + return s; + + case CONTINUE: + s += "continue"; + if (stmt.getExpressionsCount() > 0) + s += "@" + prettyprint(stmt.getExpressions(0)); + return s; + + case LABEL: + s += "@" + prettyprint(stmt.getExpressions(0)); + if (stmt.getExpressionsCount() > 1) + s += " " + prettyprint(stmt.getExpressions(1)); + return s; + + case CASE: + return prettyprint(stmt.getExpressions(0)) + " -> "; + + case DEFAULT: + return "else -> "; + + case EXPRESSION: + return prettyprint(stmt.getExpressions(0)) + "\n"; + + case TYPEDECL: + return prettyprint(stmt.getTypeDeclaration()); + + case CATCH: + s += indent() + "catch ("; + s += prettyprint(stmt.getVariableDeclaration()); + s += ") {\n"; + indent++; + for (int i = 0; i < stmt.getStatementsCount(); i++) + s += indent() + prettyprint(stmt.getStatements(i)) + "\n"; + indent--; + s += indent() + "}"; + return s; + + case FINALLY: + s += indent() + "finally {\n"; + indent++; + for (int i = 0; i < stmt.getStatementsCount(); i++) + s += indent() + prettyprint(stmt.getStatements(i)) + "\n"; + indent--; + s += indent() + "}"; + return s; + + case TRY: + s += "try {\n"; + indent++; + for (int i = 0; i < stmt.getStatementsCount(); i++) + s += prettyprint(stmt.getStatements(i)) + "\n"; + indent--; + s += indent() + "}"; + return s; + + case FOREACH: + s += "for ("; + if (stmt.getVariableDeclarationsCount() == 1) + s += prettyprint(stmt.getVariableDeclarations(0)); + else { + s += "("; + for (int i = 0 ; i < stmt.getVariableDeclarationsCount() ; i++) { + if (i > 0) s += ", "; + s += prettyprint(stmt.getVariableDeclarations(i)); + } + s += ")"; + } + s += " in " + prettyprint(stmt.getInitializations(0)) + ")\n"; + s += indent() + prettyprint(stmt.getStatements(0)); + return s; + + case DO: + s += "do "; + for (int i = 0; i < stmt.getStatementsCount(); i++) + s += prettyprint(stmt.getStatements(i)); + s += " while (" + prettyprint(stmt.getConditions(0)) + ")"; + return s; + + case WHILE: + s += "while (" + prettyprint(stmt.getConditions(0)) + ")"; + if (stmt.getExpressionsCount() == 0) { + s += " "; + for (int i = 0; i < stmt.getStatementsCount(); i++) { + if (stmt.getStatements(i).getKind() != Statement.StatementKind.BLOCK) s += indent(); + s += prettyprint(stmt.getStatements(i)); + } + } else { + s += "\n"; + indent++; + for (int i = 0; i < stmt.getExpressionsCount(); i++) + s += indent() + prettyprint(stmt.getExpressions(i)) + "\n"; + indent--; + } + return s; + + case IF: + s += "if (" + prettyprint(stmt.getConditions(0)) + ")\n"; + indent++; + s += indent() + prettyprint(stmt.getStatements(0)) + "\n"; + indent--; + if (stmt.getStatementsCount() > 1) { + s += indent() + "else\n"; + indent++; + s += indent() + prettyprint(stmt.getStatements(1)) + "\n"; + indent--; + } + return s; + + case SWITCH: + s += "when"; + if (stmt.getConditionsCount() > 0) + s += " (" + prettyprint(stmt.getConditions(0)) + ")"; + s += " {\n"; + indent++; + for (int i = 0; i < stmt.getStatementsCount(); i++) + s += indent() + prettyprint(stmt.getStatements(i)) + "\n"; + indent--; + s += indent() + "}"; + return s; + + case THROW: + if (stmt.getExpressionsCount() == 0) + return "throw"; + return "throw " + prettyprint(stmt.getExpressions(0)); + + default: return s; + } + } + + public String prettyprint(final Expression e) { + // FIXME convert to Kotlin + if (e == null) return ""; + + String s = ""; + + if (e.getModifiersCount() > 0) { + for(int i = 0 ; i < e.getModifiersCount() ; i++) { + s += prettyprint(e.getModifiers(i)) + " "; + } + } + + switch (e.getKind()) { + case OP_ADD: + if (e.getExpressionsCount() == 1) + return ppPrefix("+", e); + return ppInfix("+", e.getExpressionsList()); + case OP_SUB: + if (e.getExpressionsCount() == 1) + return ppPrefix("-", e); + return ppInfix("-", e.getExpressionsList()); + + case LOGICAL_AND: return "(" + ppInfix("&&", e.getExpressionsList()) + ")"; + case LOGICAL_OR: return "(" + ppInfix("||", e.getExpressionsList()) + ")"; + + case EQ: return ppInfix("==", e.getExpressionsList()); + case NEQ: return ppInfix("!=", e.getExpressionsList()); + case LT: return ppInfix("<", e.getExpressionsList()); + case GT: return ppInfix(">", e.getExpressionsList()); + case LTEQ: return ppInfix("<=", e.getExpressionsList()); + case GTEQ: return ppInfix(">=", e.getExpressionsList()); + case OP_DIV: return ppInfix("/", e.getExpressionsList()); + case OP_MULT: return ppInfix("*", e.getExpressionsList()); + case OP_MOD: return ppInfix("%", e.getExpressionsList()); + case BIT_AND: return ppInfix("&", e.getExpressionsList()); + case BIT_OR: return ppInfix("|", e.getExpressionsList()); + case BIT_XOR: return ppInfix("^", e.getExpressionsList()); + case BIT_LSHIFT: return ppInfix("<<", e.getExpressionsList()); + case BIT_RSHIFT: return ppInfix(">>", e.getExpressionsList()); + case BIT_UNSIGNEDRSHIFT: return ppInfix(">>>", e.getExpressionsList()); + case ASSIGN: return ppInfix("=", e.getExpressionsList()); + case ASSIGN_ADD: return ppInfix("+=", e.getExpressionsList()); + case ASSIGN_SUB: return ppInfix("-=", e.getExpressionsList()); + case ASSIGN_MULT: return ppInfix("*=", e.getExpressionsList()); + case ASSIGN_DIV: return ppInfix("/=", e.getExpressionsList()); + case ASSIGN_MOD: return ppInfix("%=", e.getExpressionsList()); + case ASSIGN_BITXOR: return ppInfix("^=", e.getExpressionsList()); + case ASSIGN_BITAND: return ppInfix("&=", e.getExpressionsList()); + case ASSIGN_BITOR: return ppInfix("|=", e.getExpressionsList()); + case ASSIGN_LSHIFT: return ppInfix("<<=", e.getExpressionsList()); + case ASSIGN_RSHIFT: return ppInfix(">>=", e.getExpressionsList()); + case ASSIGN_UNSIGNEDRSHIFT: return ppInfix(">>>=", e.getExpressionsList()); + case ARRAY_COMPREHENSION: + if (e.getExpressionsCount() == 2) { + return ppInfix((e.hasLiteral() ? e.getLiteral() : ".."), e.getExpressionsList()); + } else if (e.getExpressionsCount() == 3) { + s += prettyprint(e.getExpressions(0)); + s += " " + (e.hasLiteral() ? e.getLiteral() : "..") + " "; + s += prettyprint(e.getExpressions(1)); + s += " step "; + s += prettyprint(e.getExpressions(2)); + } + return s; + + case LOGICAL_NOT: return ppPrefix("!", e); + case BIT_NOT: return ppPrefix("~", e); + + case OP_DEC: + if (e.getIsPostfix()) + return ppPostfix("--", e); + return ppPrefix("--", e); + case OP_INC: + if (e.getIsPostfix()) + return ppPostfix("++", e); + return ppPrefix("++", e); + + case PAREN: + if (e.getExpressionsCount() == 0) + return "()"; + return "(" + prettyprint(e.getExpressions(0)) + ")"; + + case LABEL: return e.getLiteral(); + case LITERAL: return e.getLiteral(); + + case VARACCESS: + for (int i = 0; i < e.getExpressionsCount(); i++) + s += prettyprint(e.getExpressions(i)) + "."; + s += e.getVariable(); + if (e.getGenericParametersCount() > 0) { + s += "<"; + for (int i = 0 ; i < e.getGenericParametersCount(); i++) { + if (i > 0) s += ", "; + s += prettyprint(e.getGenericParameters(i)); + } + s += ">"; + } + return s; + + case CAST: + s += "(" + e.getNewType().getName() + ")"; + if (e.getExpressionsCount() > 0) + s += prettyprint(e.getExpressions(0)); + return s; + + case CONDITIONAL: return prettyprint(e.getExpressions(0)) + " ? " + prettyprint(e.getExpressions(1)) + " : " + prettyprint(e.getExpressions(2)); + case NULLCOALESCE: return prettyprint(e.getExpressions(0)) + " ?? " + prettyprint(e.getExpressions(1)); + + case METHODCALL: + for (int i = 0; i < e.getExpressionsCount(); i++) + s += prettyprint(e.getExpressions(i)) + "."; + s += e.getMethod(); + if (e.getGenericParametersCount() > 0) { + s += "<"; + for (int i = 0; i < e.getGenericParametersCount(); i++) { + if (i > 0) + s += ", "; + s += prettyprint(e.getGenericParameters(i)); + } + s += ">"; + } + s += "("; + for (int i = 0; i < e.getMethodArgsCount(); i++) { + if (i > 0) + s += ", "; + s += prettyprint(e.getMethodArgs(i)); + } + s += ")"; + return s; + + case TYPECOMPARE: + if (e.getExpressionsCount() == 1) + s += prettyprint(e.getExpressions(0)) + " "; + s += "is " + prettyprint(e.getNewType()); + return s; + + case NEWARRAY: + s += "new "; + final String arrtype = prettyprint(e.getNewType()); + s += arrtype.substring(0, arrtype.length() - 1); + for (int i = 0; i < e.getExpressionsCount(); i++) + s += prettyprint(e.getExpressions(i)); + s += "]"; + return s; + + case NEW: + s += "new "; + s += prettyprint(e.getNewType()); + if (e.getGenericParametersCount() > 0) { + s += "<"; + for (int i = 0; i < e.getGenericParametersCount(); i++) { + if (i > 0) + s += ", "; + s += prettyprint(e.getGenericParameters(i)); + } + s += ">"; + } + s += "("; + for (int i = 0; i < e.getMethodArgsCount(); i++) { + if (i > 0) + s += ", "; + s += prettyprint(e.getMethodArgs(i)); + } + s += ")"; + if (e.hasAnonDeclaration()) + s += prettyprint(e.getAnonDeclaration()); + return s; + + case ARRAYACCESS: + return prettyprint(e.getExpressions(0)) + "[" + prettyprint(e.getExpressions(1)) + "]"; + + case ARRAYINIT: + s += "{"; + for (int i = 0; i < e.getExpressionsCount(); i++) { + if (i > 0) + s += ", "; + s += prettyprint(e.getExpressions(i)); + } + s += "}"; + return s; + + case ANNOTATION: + return prettyprint(e.getModifiersList()); + + case VARDECL: + for (int i = 0; i < e.getVariableDeclsCount(); i++) { + s += prettyprint(e.getVariableDecls(i)); + } + + return s; + + case IN: + if (e.getExpressionsCount() > 1) { + s += prettyprint(e.getExpressions(0)) + " in " + prettyprint(e.getExpressions(1)); + } else if (e.getExpressionsCount() > 0) { + s += "in " + prettyprint(e.getExpressions(0)); + } + return s; + + case LAMBDA: + s += "{ "; + for (int i = 0; i < e.getVariableDeclsCount(); i++) { + if (i > 0) + s += ", "; + s+= prettyprint(e.getVariableDecls(i)); + } + if (e.getVariableDeclsCount() > 0) + s += " -> "; + if (e.getStatementsCount() != 0) + s += prettyprint(e.getStatements(0)); + if (e.getExpressionsCount() != 0) + for(int i = 0 ; i < e.getExpressionsCount() ; i++) { + if (i > 0) s += " "; + s += prettyprint(e.getExpressions(i)); + } + s += " }"; + return s; + + case STATEMENT: + for (int i = 0 ; i < e.getStatementsCount() ; i++) + s += prettyprint(e.getStatements(i)); + return s; + + case TEMPLATE: + s += e.getLiteral(); + return s; + + case METHOD_REFERENCE: + for (int i = 0 ; i < e.getExpressionsCount() ; i ++) { + s += prettyprint(e.getExpressions(i)); + s += "::"; + } + s += e.getMethod(); + return s; + + default: return s; + } + } + + private String ppPrefix(final String op, final Expression e) { + return op + prettyprint(e.getExpressions(0)); + } + + private String ppPostfix(final String op, final Expression e) { + return prettyprint(e.getExpressions(0)) + op; + } + + private String ppInfix(final String op, final List exps) { + StringBuilder s = new StringBuilder(); + + if (exps.size() == 1) { + s.append(op); + s.append(prettyprint(exps.get(0))); + } else { + s.append(prettyprint(exps.get(0))); + for (int i = 1; i < exps.size(); i++) { + s.append(" "); + s.append(op); + s.append(" "); + s.append(prettyprint(exps.get(i))); + } + } + + return s.toString(); + } + + public String prettyprint(final Modifier m) { + if (m == null) return ""; + + switch (m.getKind()) { + case VISIBILITY: + switch (m.getVisibility()) { + case PUBLIC: return "public"; + case PRIVATE: return "private"; + case PROTECTED: return "protected"; + case INTERNAL: return "internal"; + default: return ""; + } + + case ANNOTATION: + String s = "@"; + if (m.hasOther()) + s += m.getOther() + ":"; + s += m.getAnnotationName(); + if (m.getAnnotationValuesCount() > 0) s += "("; + for (int i = 0; i < m.getAnnotationValuesCount(); i++) { + if (i > 0) s += ", "; + s += prettyprint(m.getAnnotationValues(i)); + } + if (m.getAnnotationValuesCount() > 0) s += ")"; + return s; + + case FINAL: return "final"; + case ABSTRACT: return "abstract"; + + default: return m.getOther(); + } + } + + public Expression parseexpression(final String content) { + final ASTRoot root = parse(content); + if (root.getNamespacesCount() == 0) return null; + final Namespace n = root.getNamespaces(0); + if (n.getExpressionsCount() == 0) return null; + return n.getExpressions(0); + } + + private static PsiManager kProjectManager = null; + + public static KtFile tryparse(final String path, final String content, final boolean debug) { + try { + if (kProjectManager == null) { + final Disposable disp = Disposer.newDisposable(); + final KotlinCoreApplicationEnvironment kae = KotlinCoreApplicationEnvironment.create(disp, false); + final Project proj = new KotlinCoreProjectEnvironment(disp, kae).getProject(); + ((CoreFileTypeRegistry)FileTypeRegistry.getInstance()).registerFileType(KotlinFileType.INSTANCE, "kt"); + ((CoreFileTypeRegistry)FileTypeRegistry.getInstance()).registerFileType(KotlinFileType.INSTANCE, "kts"); + LanguageParserDefinitions.INSTANCE.addExplicitExtension(KotlinLanguage.INSTANCE, + new KotlinParserDefinition()); + kProjectManager = PsiManager.getInstance(proj); + } + + final VirtualFile file = new LightVirtualFile(path, KotlinFileType.INSTANCE, content.replaceAll("\r\n", "\n")); + final KtFile theKt = new KtFile(kProjectManager.findViewProvider(file), false); + + if (!debug && new KotlinErrorCheckVisitor().hasError(theKt)) + return null; + + return theKt; + } catch (final Exception e) { + if (debug) throw e; + return null; + } + } + private static final KotlinVisitor visitor = new KotlinVisitor(); + + public ASTRoot parse(final String content) { + final ASTRoot.Builder ast = ASTRoot.newBuilder(); + + final KtFile theKt = tryparse("boa.kt", content, false); + if (theKt != null) + ast.addNamespaces(visitor.getNamespace(theKt)); + + return ast.build(); + } +} diff --git a/src/java/boa/runtime/BoaAbstractVisitor.java b/src/java/boa/runtime/BoaAbstractVisitor.java index 32318827c..5bd5212d3 100644 --- a/src/java/boa/runtime/BoaAbstractVisitor.java +++ b/src/java/boa/runtime/BoaAbstractVisitor.java @@ -325,6 +325,9 @@ public final void visit(final Type node) throws Exception { if (node.hasComputedName()) visit(node.getComputedName()); + if (node.hasDelegate()) + visit(node.getDelegate()); + postVisit(node); } } @@ -361,6 +364,12 @@ public final void visit(final Method node) throws Exception { if (node.hasComputedName()) visit(node.getComputedName()); + if (node.hasExpression()) + visit(node.getExpression()); + + if (node.hasReceiverType()) + visit(node.getReceiverType()); + postVisit(node); } } @@ -467,8 +476,10 @@ public final void visit(final Expression node) throws Exception { if (node.hasAnonDeclaration()) visit(node.getAnonDeclaration()); - if (node.hasAnnotation()) - visit(node.getAnnotation()); + final List modifiersList = node.getModifiersList(); + final int modifiersSize = modifiersList.size(); + for (int i = 0 ; i < modifiersSize; i++) + visit(modifiersList.get(i)); if (node.hasDeclaringType()) visit(node.getDeclaringType()); diff --git a/src/java/boa/types/proto/ExpressionProtoTuple.java b/src/java/boa/types/proto/ExpressionProtoTuple.java index c0630e55e..b7f06b777 100644 --- a/src/java/boa/types/proto/ExpressionProtoTuple.java +++ b/src/java/boa/types/proto/ExpressionProtoTuple.java @@ -1,6 +1,7 @@ /* - * Copyright 2014, Hridesh Rajan, Robert Dyer, - * and Iowa State University of Science and Technology + * Copyright 2014-2021, Hridesh Rajan, Robert Dyer, + * Iowa State University of Science and Technology + * and University of Nebraska Board of Regents * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,8 +75,8 @@ public class ExpressionProtoTuple extends BoaProtoTuple { names.put("anon_declaration", counter++); members.add(new DeclarationProtoTuple()); - names.put("annotation", counter++); - members.add(new ModifierProtoTuple()); + names.put("modifiers", counter++); + members.add(new BoaProtoList(new ModifierProtoTuple())); names.put("no_parens", counter++); members.add(new BoaBool()); @@ -115,6 +116,9 @@ public class ExpressionProtoTuple extends BoaProtoTuple { names.put("trait", counter++); members.add(new MethodProtoTuple()); + + names.put("safe", counter++); + members.add(new BoaBool()); } /** diff --git a/src/java/boa/types/proto/MethodProtoTuple.java b/src/java/boa/types/proto/MethodProtoTuple.java index f5dca9cf7..812f7facd 100644 --- a/src/java/boa/types/proto/MethodProtoTuple.java +++ b/src/java/boa/types/proto/MethodProtoTuple.java @@ -1,6 +1,7 @@ /* - * Copyright 2014, Hridesh Rajan, Robert Dyer, - * and Iowa State University of Science and Technology + * Copyright 2014-2021, Hridesh Rajan, Robert Dyer, + * Iowa State University of Science and Technology + * and University of Nebraska Board of Regents * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,6 +72,12 @@ public class MethodProtoTuple extends BoaProtoTuple { names.put("computed_name", counter++); members.add(new ExpressionProtoTuple()); + + names.put("expression", counter++); + members.add(new ExpressionProtoTuple()); + + names.put("receiver_type", counter++); + members.add(new TypeProtoTuple()); } /** diff --git a/src/java/boa/types/proto/TypeProtoTuple.java b/src/java/boa/types/proto/TypeProtoTuple.java index 72eee6867..6f9923233 100644 --- a/src/java/boa/types/proto/TypeProtoTuple.java +++ b/src/java/boa/types/proto/TypeProtoTuple.java @@ -1,6 +1,7 @@ /* - * Copyright 2014, Hridesh Rajan, Robert Dyer, - * and Iowa State University of Science and Technology + * Copyright 2014-2021, Hridesh Rajan, Robert Dyer, + * Iowa State University of Science and Technology + * and University of Nebraska Board of Regents * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,6 +63,9 @@ public class TypeProtoTuple extends BoaProtoTuple { names.put("computed_name", counter++); members.add(new ExpressionProtoTuple()); + + names.put("delegate", counter++); + members.add(new ExpressionProtoTuple()); } /** diff --git a/src/proto/ast.proto b/src/proto/ast.proto index cea8720a7..b3b1bae26 100644 --- a/src/proto/ast.proto +++ b/src/proto/ast.proto @@ -104,6 +104,16 @@ enum TypeKind { PRIMITIVE = 10; /** Array type */ ARRAY = 11; + /** Immutable data type */ + IMMUTABLE = 12; + /** A typedef/alias */ + ALIAS = 13; + /** Types declared as a singletons */ + SINGLETON = 14; + /** Types declared as explicitly dynamic */ + DYNAMIC = 15; + /** A delegated type */ + DELEGATED = 16; } /** A type in an AST */ @@ -123,6 +133,8 @@ message Type { /** */ optional int32 key = 10; optional Expression computed_name = 14; + /** For delegated types, this is the expression to delegate to. */ + optional Expression delegate = 15; } /** A method declaration */ @@ -139,11 +151,11 @@ message Method { repeated Variable arguments = 5; /** The list of exceptions thrown by this method */ repeated Type exception_types = 6; - /** + /** * The statements in the method body. Note that most methods (in C-like * languages, such as Java) contain a single statement of type BLOCK, which * contains the list of statements within it! - */ + */ repeated Statement statements = 7; /** @exclude TODO */ repeated Comment comments = 8; @@ -153,6 +165,10 @@ message Method { optional int32 declaring_type = 13; /** */ optional Expression computed_name = 14; + /** The method body expression, if the body is not composed of statements. */ + optional Expression expression = 15; + /** Reciever types */ + optional Type receiver_type = 16; } /** A variable declaration - can be a field, local, parameter, etc */ @@ -360,6 +376,12 @@ message Expression { TRAIT_ALIAS = 98; TRAIT_PRECEDENCE = 99; NAMESPACENAME = 100; + STATEMENT = 101; + TEMPLATE = 102; + LABEL = 103; + OP_ELVIS = 104; + NOT_IN = 105; + OP_NOTNULL = 106; } /** The kind of expression */ required ExpressionKind kind = 1; @@ -373,7 +395,7 @@ message Expression { optional string method = 9; repeated Expression method_args = 10; optional Declaration anon_declaration = 11; - optional Modifier annotation = 12; + repeated Modifier modifiers = 12; /** 13 used to be lambda */ /** @exclude */ optional bool no_parens = 14; @@ -394,6 +416,7 @@ message Expression { optional bool is_static = 27; optional bool has_from = 28; optional Method trait = 29; + optional bool safe = 30; } /** A single modifier */ @@ -432,6 +455,8 @@ message Modifier { TRANSIENT = 12; /** A volatile modifier */ VOLATILE = 13; + /** Modifier is implicit */ + IMPLICIT = 14; } /** A visibility modifier */ enum Visibility { @@ -448,6 +473,8 @@ message Modifier { PACKAGE = 4; /** A default visibility modifier */ DEFAULT = 5; + /** An internal visibility modifier */ + INTERNAL = 6; } /** A scope modifier */ enum Scope { diff --git a/src/proto/diff.proto b/src/proto/diff.proto index 05ab2f135..f902451da 100644 --- a/src/proto/diff.proto +++ b/src/proto/diff.proto @@ -101,6 +101,21 @@ message ChangedFile { Source_CSS = 701; /** @exclude */ CSS_ERROR = 700; + + /** The file represents a Kotlin source file that had a parse error */ + SOURCE_KOTLIN_ERROR = 800; + /** The file represents a Kotlin source file that parsed without error as 1.5.x+ */ + SOURCE_KOTLIN_1_5 = 815; + /** The file represents a Kotlin source file that parsed without error as 1.4.x+ */ + SOURCE_KOTLIN_1_4 = 814; + /** The file represents a Kotlin source file that parsed without error as 1.3.x+ */ + SOURCE_KOTLIN_1_3 = 813; + /** The file represents a Kotlin source file that parsed without error as 1.2.x+ */ + SOURCE_KOTLIN_1_2 = 812; + /** The file represents a Kotlin source file that parsed without error as 1.1.x+ */ + SOURCE_KOTLIN_1_1 = 811; + /** The file represents a Kotlin source file that parsed without error as 1.0.x+ */ + SOURCE_KOTLIN_1_0 = 810; } /** The kind of change for this file */ required ChangeKind change = 1; diff --git a/src/test/boa/test/compiler/BaseTest.java b/src/test/boa/test/compiler/BaseTest.java index 40d3aa83c..f351e938e 100644 --- a/src/test/boa/test/compiler/BaseTest.java +++ b/src/test/boa/test/compiler/BaseTest.java @@ -327,7 +327,6 @@ protected String load(final String fileName) throws IOException { } catch (IOException ex) { ex.printStackTrace(); } - } return sb.toString(); } diff --git a/src/test/boa/test/datagen/ProtoMessageVisitor.java b/src/test/boa/test/datagen/ProtoMessageVisitor.java index 640e6ac1d..0ebad56eb 100644 --- a/src/test/boa/test/datagen/ProtoMessageVisitor.java +++ b/src/test/boa/test/datagen/ProtoMessageVisitor.java @@ -18,7 +18,6 @@ public void visit(Message message) { } public boolean preVisit(Message message) { - // TODO Auto-generated method stub return true; } diff --git a/src/test/boa/test/datagen/kotlin/DumpKotlin.java b/src/test/boa/test/datagen/kotlin/DumpKotlin.java new file mode 100644 index 000000000..b2c2ca4bf --- /dev/null +++ b/src/test/boa/test/datagen/kotlin/DumpKotlin.java @@ -0,0 +1,30 @@ +/* + * Copyright 2021, Robert Dyer + * and University of Nebraska Board of Regents + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.test.datagen.kotlin; + + +/* + * @author rdyer + */ +public class DumpKotlin extends KotlinBaseTest { + public static void main(String[] args) { + if (args[1].equals("${kotlin.name}")) + dumpKotlin(args[0], "test.kt", true); + else + dumpKotlin(args[0], args[1], true); + } +} diff --git a/src/test/boa/test/datagen/kotlin/KotlinBaseTest.java b/src/test/boa/test/datagen/kotlin/KotlinBaseTest.java new file mode 100644 index 000000000..307d394d9 --- /dev/null +++ b/src/test/boa/test/datagen/kotlin/KotlinBaseTest.java @@ -0,0 +1,77 @@ +/* + * Copyright 2021, Robert Dyer, Samuel W. Flint, + * and University of Nebraska Board of Regents + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.test.datagen.kotlin; + +import com.googlecode.protobuf.format.JsonFormat; + +import org.jetbrains.kotlin.psi.KtFile; + +import boa.datagen.util.FileIO; +import boa.datagen.util.KotlinVisitor; +import boa.functions.langmode.KotlinLangMode; +import boa.test.compiler.BaseTest; +import boa.types.Ast.ASTRoot; + +/* + * @author rdyer + * @author swflint + */ +public class KotlinBaseTest extends BaseTest { + protected static void dumpKotlin(final String content) { + dumpKotlin(content, "test.kt", false); + } + + protected static void dumpKotlin(final String content, final String name) { + dumpKotlin(content, name, false); + } + + protected static void dumpKotlin(final String content, final boolean showEx) { + dumpKotlin(content, "test.kt", showEx); + } + + private final static KotlinTreeDumper treeDumper = new KotlinTreeDumper(); + + protected static void dumpKotlin(final String content, final String name, final boolean showEx) { + final KtFile theKt = KotlinLangMode.tryparse(name, content, showEx); + if (theKt == null) return; + theKt.accept(treeDumper); + } + + protected static String parseKotlin(final String content) { + return parseKotlin(content, "test.kt", false); + } + + protected static String parseKotlin(final String content, final String name) { + return parseKotlin(content, name, false); + } + + protected static String parseKotlin(final String content, final boolean showEx) { + return parseKotlin(content, "test.kt", showEx); + } + + private static final KotlinVisitor ktToBoa = new KotlinVisitor(); + + protected static String parseKotlin(final String content, final String name, final boolean showEx) { + final KtFile theKt = KotlinLangMode.tryparse(name, content, showEx); + if (theKt == null) return ""; + + final ASTRoot.Builder ast = ASTRoot.newBuilder(); + ast.addNamespaces(ktToBoa.getNamespace(theKt)); + + return FileIO.normalizeEOL(JsonFormat.printToString(ast.build())); + } +} diff --git a/src/test/boa/test/datagen/kotlin/KotlinToBoa.java b/src/test/boa/test/datagen/kotlin/KotlinToBoa.java new file mode 100644 index 000000000..a3bf36795 --- /dev/null +++ b/src/test/boa/test/datagen/kotlin/KotlinToBoa.java @@ -0,0 +1,31 @@ +/* + * Copyright 2021, Robert Dyer, Samuel W. Flint, + * and University of Nebraska Board of Regents + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.test.datagen.kotlin; + + +/* + * @author rdyer + * @author swflint + */ +public class KotlinToBoa extends KotlinBaseTest { + public static void main(String[] args) { + if (args[1].equals("${kotlin.name}")) + System.out.println(parseKotlin(args[0], "test.kt", true)); + else + System.out.println(parseKotlin(args[0], args[1], true)); + } +} diff --git a/src/test/boa/test/datagen/kotlin/KotlinTreeDumper.java b/src/test/boa/test/datagen/kotlin/KotlinTreeDumper.java new file mode 100644 index 000000000..54b358a51 --- /dev/null +++ b/src/test/boa/test/datagen/kotlin/KotlinTreeDumper.java @@ -0,0 +1,54 @@ +/* + * Copyright 2021, Robert Dyer + * and University of Nebraska Board of Regents + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.test.datagen.kotlin; + +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiWhiteSpace; +import org.jetbrains.kotlin.psi.KtVisitor; + + +/* + * @author rdyer + */ +public class KotlinTreeDumper extends KtVisitor { + private int indent = 0; + + private void indent() { + for (int i = 0; i < indent * 2; i++) + System.err.print(" "); + } + + @Override + public void visitElement(final PsiElement element) { + indent(); + System.err.print(element); + if (element instanceof org.jetbrains.kotlin.psi.KtConstantExpression) + System.err.print("(" + ((org.jetbrains.kotlin.psi.KtConstantExpression)element).getText() + ")"); + else if (element instanceof org.jetbrains.kotlin.psi.KtBinaryExpression) + System.err.print("(" + ((org.jetbrains.kotlin.psi.KtBinaryExpression)element).getOperationToken() + ")"); + else if (element instanceof com.intellij.psi.impl.source.tree.LeafPsiElement) + System.err.print("(" + ((com.intellij.psi.impl.source.tree.LeafPsiElement)element).getText() + ")"); + System.err.println(" - " + element.getClass()); + indent++; + element.acceptChildren(this); + indent--; + } + + @Override + public void visitWhiteSpace(final PsiWhiteSpace space) { + } +} diff --git a/src/test/boa/test/datagen/kotlin/SaveKotlinTestResult.java b/src/test/boa/test/datagen/kotlin/SaveKotlinTestResult.java new file mode 100644 index 000000000..04135d150 --- /dev/null +++ b/src/test/boa/test/datagen/kotlin/SaveKotlinTestResult.java @@ -0,0 +1,81 @@ +/* + * Copyright 2021, Robert Dyer + * and University of Nebraska Board of Regents + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.test.datagen.kotlin; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import boa.datagen.util.FileIO; +import boa.datagen.util.KotlinErrorCheckVisitor; +import boa.functions.langmode.KotlinLangMode; + +/** + * @author rdyer + */ +@RunWith(Parameterized.class) +public class SaveKotlinTestResult extends KotlinBaseTest { + final private static String rootDir = "test/datagen/kotlin"; + + @Parameters(name = "{0}") + public static List data() { + return getData(new File(rootDir)); + } + + private static List getData(final File root) { + final List files = new ArrayList(); + for (final File f : root.listFiles()) + if (f.isDirectory()) { + files.addAll(getData(f)); + } else if (f.getName().endsWith(".kt")) { + final File f2 = new File(f.getPath().replace(".kt", ".json")); + if (f2.exists() && !f2.isDirectory()) + files.add(new String[] { f.getPath(), f2.getPath()}); + } + return files; + } + + private String kotlinFileName; + private String jsonFileName; + private String actualJsonFileName; + public SaveKotlinTestResult(final String kotlinFileName, final String jsonFileName) { + this.kotlinFileName = kotlinFileName; + this.actualJsonFileName = jsonFileName; + this.jsonFileName = jsonFileName + "2"; + } + + private final KotlinErrorCheckVisitor errorCheck = new KotlinErrorCheckVisitor(); + + @Test + public void saveKotlinResult() throws IOException { + final String src = load(kotlinFileName); + final String content = parseKotlin(src).trim(); + if (errorCheck.hasError(KotlinLangMode.tryparse("test.kt", src, false))) { + boa.datagen.util.FileIO.writeFileContents(new File(jsonFileName + ".error"), content, false); + } else { + FileIO.delete(new File(jsonFileName)); + if (!content.equals(load(actualJsonFileName).trim())) + boa.datagen.util.FileIO.writeFileContents(new File(jsonFileName), content, false); + } + } +} diff --git a/src/test/boa/test/datagen/kotlin/TestKotlin.java b/src/test/boa/test/datagen/kotlin/TestKotlin.java new file mode 100644 index 000000000..3dce320cd --- /dev/null +++ b/src/test/boa/test/datagen/kotlin/TestKotlin.java @@ -0,0 +1,92 @@ +/* + * Copyright 2021, Robert Dyer + * and University of Nebraska Board of Regents + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.test.datagen.kotlin; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * @author rdyer + */ +@RunWith(Parameterized.class) +public class TestKotlin extends KotlinBaseTest { + final private static String rootDir = "test/datagen/kotlin"; + + public static class FileTestCaseComparator implements Comparator { + @Override + public int compare(final String[] o1, final String[] o2) { + return o1[0].compareTo(o2[0]); + } + } + + @Parameters(name = "{0}") + public static List data() { + final String filename = System.getProperty("test.args"); + if (filename != null) { + final File f = new File(filename); + if (f.exists() && !f.isDirectory()) { + final List data = new ArrayList(); + data.add(new String[] { f.getPath(), new File(f.getPath().replace(".kt", ".json")).getPath() }); + return data; + } + } + + final List data = getData(new File(rootDir)); + Collections.sort(data, new FileTestCaseComparator()); + return data; + } + + private static List getData(final File root) { + final List files = new ArrayList(); + for (final File f : root.listFiles()) + if (f.isDirectory()) { + files.addAll(getData(f)); + } else if (f.getName().endsWith(".kt")) { + final File f2 = new File(f.getPath().replace(".kt", ".json")); + if (f2.exists() && !f2.isDirectory()) + files.add(new String[] { f.getPath(), f2.getPath()}); + } + return files; + } + + private String kotlinFileName; + private String jsonFileName; + public TestKotlin(final String kotlinFileName, final String jsonFileName) { + this.kotlinFileName = kotlinFileName; + this.jsonFileName = jsonFileName; + } + + + // test a bunch of known good files + @Test + public void kotlin() throws IOException { + assertEquals( + load(jsonFileName).trim(), + parseKotlin(load(kotlinFileName)).trim() + ); + } +} diff --git a/test/datagen/kotlin/annotated-expr.json b/test/datagen/kotlin/annotated-expr.json new file mode 100644 index 000000000..a45835db2 --- /dev/null +++ b/test/datagen/kotlin/annotated-expr.json @@ -0,0 +1,50 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "STATEMENT", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Suppress", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "\"UNCHECKED_CAST\"" + } + ] + } + ], + "statements": [ + { + "kind": "RETURN" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/annotated-expr.kt b/test/datagen/kotlin/annotated-expr.kt new file mode 100644 index 000000000..374c7b4cb --- /dev/null +++ b/test/datagen/kotlin/annotated-expr.kt @@ -0,0 +1,6 @@ +class C { + fun f() { + @Suppress("UNCHECKED_CAST") + return + } +} diff --git a/test/datagen/kotlin/annotated-for.json b/test/datagen/kotlin/annotated-for.json new file mode 100644 index 000000000..4c69b3f77 --- /dev/null +++ b/test/datagen/kotlin/annotated-for.json @@ -0,0 +1,92 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "STATEMENT", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Suppress", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "\"UNUSED_VARIABLE\"" + } + ] + } + ], + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"hi\"" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "variable_declarations": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/annotated-for.kt b/test/datagen/kotlin/annotated-for.kt new file mode 100644 index 000000000..f154182bd --- /dev/null +++ b/test/datagen/kotlin/annotated-for.kt @@ -0,0 +1,8 @@ +class C { + fun f() { + @Suppress("UNUSED_VARIABLE") + for (x in y) { + println("hi") + } + } +} diff --git a/test/datagen/kotlin/annotations.json b/test/datagen/kotlin/annotations.json new file mode 100644 index 000000000..43d7fec9c --- /dev/null +++ b/test/datagen/kotlin/annotations.json @@ -0,0 +1,228 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Example", + "kind": "IMMUTABLE", + "modifiers": [ + { + "kind": "OTHER", + "other": "data" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "foo", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "field" + } + ] + }, + { + "name": "bar", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "get" + } + ] + }, + { + "name": "quux", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "param" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "foo", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "field" + } + ] + }, + { + "name": "bar", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "get" + } + ] + }, + { + "name": "quux", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "param" + } + ] + } + ] + }, + { + "name": "C", + "kind": "CLASS", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "3" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Ann1", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "5" + }, + { + "kind": "VARACCESS", + "variable": "x" + } + ] + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann2" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann3", + "annotation_values": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "str" + }, + { + "kind": "LITERAL", + "literal": "\"hi\"" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/annotations.kt b/test/datagen/kotlin/annotations.kt new file mode 100644 index 000000000..0eee4d6a2 --- /dev/null +++ b/test/datagen/kotlin/annotations.kt @@ -0,0 +1,8 @@ +data class Example(@field:Ann val foo: Int, @get:Ann val bar: String, @param:Ann val quux: String) + +class C { + fun f() { + val x = 3 + @Ann1(5, x) @Ann2 @Ann3(str = "hi") print(x) + } +} diff --git a/test/datagen/kotlin/annotations2.json b/test/datagen/kotlin/annotations2.json new file mode 100644 index 000000000..83ea7a469 --- /dev/null +++ b/test/datagen/kotlin/annotations2.json @@ -0,0 +1,406 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "ann", + "kind": "ANNOTATION", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Retention", + "annotation_values": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "AnnotationRetention" + } + ], + "variable": "SOURCE" + } + ] + }, + { + "kind": "ANNOTATION", + "annotation_name": "Repeatable" + }, + { + "kind": "OTHER", + "other": "annotation" + } + ] + } + ], + "methods": [ + { + "name": "bar", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "() -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "() -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "LAMBDA", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "LAMBDA", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + }, + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "LAMBDA", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "LAMBDA", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "LAMBDA", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + }, + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "LAMBDA", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "STATEMENT", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "STATEMENT", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + }, + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LITERAL", + "literal": "true" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/annotations2.kt b/test/datagen/kotlin/annotations2.kt new file mode 100644 index 000000000..4795bda0b --- /dev/null +++ b/test/datagen/kotlin/annotations2.kt @@ -0,0 +1,36 @@ +@Retention(AnnotationRetention.SOURCE) @Repeatable annotation class ann + +fun bar(x: () -> Unit) {} + +fun foo(x: () -> Unit) { + bar @ann { + print(1) + } + + bar @ann @[ann] { + print(2) + } + + bar() @ann { + print(1) + } + + bar() @[ann] { + print(2) + } + + bar() @ann @[ann] { + print(2) + } + + bar(@ann { + print(3) + }) + + if (true) @ann { + + } + else @[ann] @ann { + + } +} diff --git a/test/datagen/kotlin/anon-innerclass.json b/test/datagen/kotlin/anon-innerclass.json new file mode 100644 index 000000000..dd0264292 --- /dev/null +++ b/test/datagen/kotlin/anon-innerclass.json @@ -0,0 +1,111 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "window" + } + ], + "method": "addMouseListener", + "method_args": [ + { + "kind": "NEW", + "new_type": { + "name": "MouseAdapter", + "kind": "CLASS" + }, + "anon_declaration": { + "name": "", + "kind": "SINGLETON", + "parents": [ + { + "name": "MouseAdapter", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "mouseClicked", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "e", + "variable_type": { + "name": "MouseEvent", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "mouseEntered", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "e", + "variable_type": { + "name": "MouseEvent", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + } + ] + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/anon-innerclass.kt b/test/datagen/kotlin/anon-innerclass.kt new file mode 100644 index 000000000..8ac77797b --- /dev/null +++ b/test/datagen/kotlin/anon-innerclass.kt @@ -0,0 +1,5 @@ +val x = window.addMouseListener(object : MouseAdapter() { + override fun mouseClicked(e: MouseEvent) { } + + override fun mouseEntered(e: MouseEvent) { } +}) diff --git a/test/datagen/kotlin/anonclass-func.json b/test/datagen/kotlin/anonclass-func.json new file mode 100644 index 000000000..2bd376d20 --- /dev/null +++ b/test/datagen/kotlin/anonclass-func.json @@ -0,0 +1,49 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "listener", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "ActionListener", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"clicked\"" + } + ] + } + ] + } + ] + } + ] + } + ] + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/anonclass-func.kt b/test/datagen/kotlin/anonclass-func.kt new file mode 100644 index 000000000..6a9beced6 --- /dev/null +++ b/test/datagen/kotlin/anonclass-func.kt @@ -0,0 +1 @@ +val listener = ActionListener { println("clicked") } diff --git a/test/datagen/kotlin/arithmetic.json b/test/datagen/kotlin/arithmetic.json new file mode 100644 index 000000000..9b95f4d4c --- /dev/null +++ b/test/datagen/kotlin/arithmetic.json @@ -0,0 +1,73 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "variables": [ + { + "name": "pi", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "3.14159" + } + }, + { + "name": "x", + "variable_type": { + "name": "int", + "kind": "OTHER" + }, + "initializer": { + "kind": "OP_DIV", + "expressions": [ + { + "kind": "OP_MULT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "5" + }, + { + "kind": "PAREN", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + }, + { + "kind": "LITERAL", + "literal": "7" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "pi" + } + ] + } + ] + } + ] + }, + { + "kind": "LITERAL", + "literal": "6" + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/arithmetic.kt b/test/datagen/kotlin/arithmetic.kt new file mode 100644 index 000000000..7ef819298 --- /dev/null +++ b/test/datagen/kotlin/arithmetic.kt @@ -0,0 +1,5 @@ +package boa.kotlin.test + +val pi = 3.14159 + +var x: int = 5 * (3 + 7 + pi) / 6 \ No newline at end of file diff --git a/test/datagen/kotlin/array-access.json b/test/datagen/kotlin/array-access.json new file mode 100644 index 000000000..7130e193c --- /dev/null +++ b/test/datagen/kotlin/array-access.json @@ -0,0 +1,60 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "variables": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + }, + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "bar" + }, + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "METHODCALL", + "method": "foo" + } + ] + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/array-access.kt b/test/datagen/kotlin/array-access.kt new file mode 100644 index 000000000..638188959 --- /dev/null +++ b/test/datagen/kotlin/array-access.kt @@ -0,0 +1,4 @@ +package boa.kotlin.test + +val x = foo[y] +val y = bar[1 + foo()] \ No newline at end of file diff --git a/test/datagen/kotlin/binary-expressions.json b/test/datagen/kotlin/binary-expressions.json new file mode 100644 index 000000000..6d1dc2967 --- /dev/null +++ b/test/datagen/kotlin/binary-expressions.json @@ -0,0 +1,469 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_MULT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_DIV", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_MOD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_MULT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_DIV", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_MOD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LTEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "GTEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "NEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LOGICAL_AND", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LOGICAL_OR", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "BIT_AND", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "BIT_OR", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "BIT_XOR", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "BIT_LSHIFT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "BIT_RSHIFT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "BIT_UNSIGNEDRSHIFT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/binary-expressions.kt b/test/datagen/kotlin/binary-expressions.kt new file mode 100644 index 000000000..4f4354af1 --- /dev/null +++ b/test/datagen/kotlin/binary-expressions.kt @@ -0,0 +1,38 @@ +package boa.kotlin.test + +fun foo() { + // Assignments + x = 5 + x += 5 + x -= 5 + x *= 5 + x /= 5 + x %= 5 + + // Arithmetic + x - 5 + x + 5 + x * 5 + x / 5 + x % 5 + + // Comparison + x <= 5 + x >= 5 + x > 5 + x < 5 + x == 5 + x != 5 + + // Logical + x && y + x || y + + // Bitwise + x and y + x or y + x xor y + x shl y + x shr y + x ushr y +} diff --git a/test/datagen/kotlin/break.json b/test/datagen/kotlin/break.json new file mode 100644 index 000000000..b1540b435 --- /dev/null +++ b/test/datagen/kotlin/break.json @@ -0,0 +1,98 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "main", + "arguments": [ + { + "name": "args", + "variable_type": { + "name": "Array", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "5" + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BREAK" + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BREAK", + "expressions": [ + { + "kind": "LABEL", + "literal": "first" + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/break.kt b/test/datagen/kotlin/break.kt new file mode 100644 index 000000000..204b99efa --- /dev/null +++ b/test/datagen/kotlin/break.kt @@ -0,0 +1,7 @@ +fun main(args: Array) { + val x = 5 + if (x) + break + if (!x) + break@first +} diff --git a/test/datagen/kotlin/bug.json b/test/datagen/kotlin/bug.json new file mode 100644 index 000000000..90fd63a7e --- /dev/null +++ b/test/datagen/kotlin/bug.json @@ -0,0 +1,58 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "String", + "kind": "OTHER" + }, + "expression": { + "kind": "LITERAL", + "literal": "\"hi\"" + }, + "receiver_type": { + "name": "String", + "kind": "OTHER" + } + } + ] + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/bug.kt b/test/datagen/kotlin/bug.kt new file mode 100644 index 000000000..575e700cf --- /dev/null +++ b/test/datagen/kotlin/bug.kt @@ -0,0 +1,3 @@ +fun f() { + val x = fun String.(): String = "hi" +} diff --git a/test/datagen/kotlin/bug2.json b/test/datagen/kotlin/bug2.json new file mode 100644 index 000000000..b9de43846 --- /dev/null +++ b/test/datagen/kotlin/bug2.json @@ -0,0 +1,94 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "5" + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "OP_MOD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "number" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/bug2.kt b/test/datagen/kotlin/bug2.kt new file mode 100644 index 000000000..91e8fffb6 --- /dev/null +++ b/test/datagen/kotlin/bug2.kt @@ -0,0 +1,3 @@ +fun f() { + (1..5 step if (number % 2 == 0) 1 else 2) +} diff --git a/test/datagen/kotlin/bug4.json b/test/datagen/kotlin/bug4.json new file mode 100644 index 000000000..f98e4268b --- /dev/null +++ b/test/datagen/kotlin/bug4.json @@ -0,0 +1,92 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"bar\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "STATEMENT", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"foo\"" + } + ] + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/bug4.kt b/test/datagen/kotlin/bug4.kt new file mode 100644 index 000000000..fb8bbcfe0 --- /dev/null +++ b/test/datagen/kotlin/bug4.kt @@ -0,0 +1,5 @@ +fun f() { + val x = if (y) "bar" else @Ann { + "foo" + } +} diff --git a/test/datagen/kotlin/bug5.json b/test/datagen/kotlin/bug5.json new file mode 100644 index 000000000..206254e87 --- /dev/null +++ b/test/datagen/kotlin/bug5.json @@ -0,0 +1,39 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f", + "expression": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "ExampleIndices" + }, + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "indices" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/bug5.kt b/test/datagen/kotlin/bug5.kt new file mode 100644 index 000000000..8f354a6e3 --- /dev/null +++ b/test/datagen/kotlin/bug5.kt @@ -0,0 +1 @@ +fun f() = ExampleIndices@indices[0] diff --git a/test/datagen/kotlin/callable-method-reference.json b/test/datagen/kotlin/callable-method-reference.json new file mode 100644 index 000000000..a64c86b33 --- /dev/null +++ b/test/datagen/kotlin/callable-method-reference.json @@ -0,0 +1,76 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "b" + } + ] + } + ], + "method": "" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ], + "method": "c" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "" + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/callable-method-reference.kt b/test/datagen/kotlin/callable-method-reference.kt new file mode 100644 index 000000000..d457bc644 --- /dev/null +++ b/test/datagen/kotlin/callable-method-reference.kt @@ -0,0 +1,4 @@ +fun foo() { + (a::b)() + a.(b::c)() +} diff --git a/test/datagen/kotlin/casts.json b/test/datagen/kotlin/casts.json new file mode 100644 index 000000000..e054f1a71 --- /dev/null +++ b/test/datagen/kotlin/casts.json @@ -0,0 +1,186 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "5" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "Float", + "kind": "OTHER" + } + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "String", + "kind": "OTHER" + } + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "String", + "kind": "OTHER" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "z", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "Float", + "kind": "OTHER" + }, + "safe": true + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/casts.kt b/test/datagen/kotlin/casts.kt new file mode 100644 index 000000000..78464f96e --- /dev/null +++ b/test/datagen/kotlin/casts.kt @@ -0,0 +1,7 @@ +fun f() { + val x = 5 + val y = x as Float + if (x is String) x = 3 + if (x !is String) x = 3 + val z = x as? Float +} diff --git a/test/datagen/kotlin/class-modifiers.json b/test/datagen/kotlin/class-modifiers.json new file mode 100644 index 000000000..3aee88154 --- /dev/null +++ b/test/datagen/kotlin/class-modifiers.json @@ -0,0 +1,57 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "C1", + "kind": "CLASS" + }, + { + "name": "C2", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ] + }, + { + "name": "C3", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ] + }, + { + "name": "C4", + "kind": "CLASS", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "C5", + "kind": "CLASS", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "ABSTRACT" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/class-modifiers.kt b/test/datagen/kotlin/class-modifiers.kt new file mode 100644 index 000000000..5545af6c9 --- /dev/null +++ b/test/datagen/kotlin/class-modifiers.kt @@ -0,0 +1,5 @@ +class C1 {} +abstract class C2 {} +open class C3 {} +final class C4 {} +final open abstract class C5 {} diff --git a/test/datagen/kotlin/class-with-companion.json b/test/datagen/kotlin/class-with-companion.json new file mode 100644 index 000000000..6d585f956 --- /dev/null +++ b/test/datagen/kotlin/class-with-companion.json @@ -0,0 +1,39 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "Six", + "kind": "CLASS", + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ], + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/class-with-companion.kt b/test/datagen/kotlin/class-with-companion.kt new file mode 100644 index 000000000..dc5241468 --- /dev/null +++ b/test/datagen/kotlin/class-with-companion.kt @@ -0,0 +1,7 @@ +package boa.kotlin.test + +class Six { + companion object { + fun foo() {} + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/complex1.json b/test/datagen/kotlin/complex1.json new file mode 100644 index 000000000..7d97f3569 --- /dev/null +++ b/test/datagen/kotlin/complex1.json @@ -0,0 +1,304 @@ +{ + "namespaces": [ + { + "name": "kotlinx.ast.common", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "\"Foo\"" + } + ], + "other": "file" + } + ], + "declarations": [ + { + "name": "AstSource", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "sealed" + } + ], + "fields": [ + { + "name": "filename", + "variable_type": { + "name": "kotlin.String?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ABSTRACT" + } + ] + }, + { + "name": "description", + "variable_type": { + "name": "kotlin.String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ABSTRACT" + } + ] + } + ], + "nested_declarations": [ + { + "name": "File", + "kind": "IMMUTABLE", + "modifiers": [ + { + "kind": "OTHER", + "other": "data" + } + ], + "parents": [ + { + "name": "AstSource", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "filename", + "variable_type": { + "name": "kotlin.String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "AstSource" + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "filename", + "variable_type": { + "name": "kotlin.String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + }, + { + "name": "description", + "variable_type": { + "name": "kotlin.String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ], + "initializer": { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"file:/\"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "filename" + } + ], + "literal": "\"$filename\"" + } + ], + "literal": "\"file:/$filename\"" + } + } + ] + }, + { + "name": "String", + "kind": "IMMUTABLE", + "modifiers": [ + { + "kind": "OTHER", + "other": "data" + } + ], + "parents": [ + { + "name": "AstSource", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "description", + "variable_type": { + "name": "kotlin.String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + }, + { + "name": "content", + "variable_type": { + "name": "kotlin.String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "AstSource" + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "description", + "variable_type": { + "name": "kotlin.String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + }, + { + "name": "content", + "variable_type": { + "name": "kotlin.String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "filename", + "variable_type": { + "name": "kotlin.String?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "null" + } + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/complex1.kt b/test/datagen/kotlin/complex1.kt new file mode 100644 index 000000000..4389f4710 --- /dev/null +++ b/test/datagen/kotlin/complex1.kt @@ -0,0 +1,18 @@ +@file:JvmName("Foo") +package kotlinx.ast.common + +sealed class AstSource { + abstract val filename: kotlin.String? + abstract val description: kotlin.String + + data class File(override val filename: kotlin.String) : AstSource() { + override val description: kotlin.String = "file:/$filename" + } + + data class String( + override val description: kotlin.String, + val content: kotlin.String + ) : AstSource() { + override val filename: kotlin.String? = null + } +} diff --git a/test/datagen/kotlin/constructor-primary.json b/test/datagen/kotlin/constructor-primary.json new file mode 100644 index 000000000..c92072285 --- /dev/null +++ b/test/datagen/kotlin/constructor-primary.json @@ -0,0 +1,82 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "Person", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "firstName", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "lastName", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "phone", + "variable_type": { + "name": "String?", + "kind": "OTHER" + } + } + ] + } + ], + "fields": [ + { + "name": "lastName", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "phone", + "variable_type": { + "name": "String?", + "kind": "OTHER" + } + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/constructor-primary.kt b/test/datagen/kotlin/constructor-primary.kt new file mode 100644 index 000000000..7f3392819 --- /dev/null +++ b/test/datagen/kotlin/constructor-primary.kt @@ -0,0 +1,5 @@ +package boa.kotlin.test + +class Person(firstName: String, val lastName: String, var phone: String?) { + +} diff --git a/test/datagen/kotlin/constructor-secondary.json b/test/datagen/kotlin/constructor-secondary.json new file mode 100644 index 000000000..e9c43b31c --- /dev/null +++ b/test/datagen/kotlin/constructor-secondary.json @@ -0,0 +1,188 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "Person", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "firstName", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "", + "arguments": [ + { + "name": "firstName", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "lastName", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "firstName" + } + ], + "method": "this" + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"hi\"" + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "firstName", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "Dog", + "kind": "CLASS", + "methods": [ + { + "name": "", + "arguments": [ + { + "name": "name", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "owner", + "variable_type": { + "name": "Person", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"woof\"" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/constructor-secondary.kt b/test/datagen/kotlin/constructor-secondary.kt new file mode 100644 index 000000000..f94c88509 --- /dev/null +++ b/test/datagen/kotlin/constructor-secondary.kt @@ -0,0 +1,13 @@ +package boa.kotlin.test + +class Person(val firstName: String) { + constructor(firstName: String, lastName: String) : this(firstName) { + println("hi") + } +} + +class Dog { + constructor(name: String, owner: Person) { + println("woof") + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/continue.json b/test/datagen/kotlin/continue.json new file mode 100644 index 000000000..30ddc21ce --- /dev/null +++ b/test/datagen/kotlin/continue.json @@ -0,0 +1,97 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "main", + "arguments": [ + { + "name": "args", + "variable_type": { + "name": "Array", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "5" + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "CONTINUE" + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "CONTINUE", + "expressions": [ + { + "kind": "LABEL", + "literal": "first" + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/continue.kt b/test/datagen/kotlin/continue.kt new file mode 100644 index 000000000..dc904a994 --- /dev/null +++ b/test/datagen/kotlin/continue.kt @@ -0,0 +1,7 @@ +fun main(args: Array) { + val x = 5 + if (x) + continue + if (!x) + continue@first +} diff --git a/test/datagen/kotlin/default-parameter.json b/test/datagen/kotlin/default-parameter.json new file mode 100644 index 000000000..a9c5e5f2d --- /dev/null +++ b/test/datagen/kotlin/default-parameter.json @@ -0,0 +1,75 @@ +{ + "namespaces": [ + { + "name": "boa.test.kotlin", + "methods": [ + { + "name": "thing", + "arguments": [ + { + "name": "name", + "variable_type": { + "name": "string", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"world\"" + } + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"Hello \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "name" + } + ], + "literal": "\"${name}\"" + }, + { + "kind": "TEMPLATE", + "literal": "\"!\"" + } + ], + "literal": "\"Hello ${name}!\"" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/default-parameter.kt b/test/datagen/kotlin/default-parameter.kt new file mode 100644 index 000000000..657ca2740 --- /dev/null +++ b/test/datagen/kotlin/default-parameter.kt @@ -0,0 +1,5 @@ +package boa.test.kotlin + +fun thing(name: string = "world") { + println("Hello ${name}!") +} \ No newline at end of file diff --git a/test/datagen/kotlin/delegate-to-if.json b/test/datagen/kotlin/delegate-to-if.json new file mode 100644 index 000000000..577986b88 --- /dev/null +++ b/test/datagen/kotlin/delegate-to-if.json @@ -0,0 +1,75 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "EdgeToEdge", + "kind": "SINGLETON", + "parents": [ + { + "name": "EdgeToEdgeImpl", + "kind": "DELEGATED", + "delegate": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "EdgeToEdgeApi21" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "EdgeToEdgeBase" + } + ] + } + ], + "conditions": [ + { + "kind": "GTEQ", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Build" + } + ], + "variable": "VERSION" + } + ], + "variable": "SDK_INT" + }, + { + "kind": "LITERAL", + "literal": "21" + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/delegate-to-if.kt b/test/datagen/kotlin/delegate-to-if.kt new file mode 100644 index 000000000..a4ae195ac --- /dev/null +++ b/test/datagen/kotlin/delegate-to-if.kt @@ -0,0 +1,2 @@ +object EdgeToEdge + : EdgeToEdgeImpl by if (Build.VERSION.SDK_INT >= 21) EdgeToEdgeApi21() else EdgeToEdgeBase() diff --git a/test/datagen/kotlin/delegated-property.json b/test/datagen/kotlin/delegated-property.json new file mode 100644 index 000000000..e66232e80 --- /dev/null +++ b/test/datagen/kotlin/delegated-property.json @@ -0,0 +1,27 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "Example", + "kind": "CLASS", + "fields": [ + { + "name": "p", + "variable_type": { + "name": "String", + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "Delegate" + } + } + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/delegated-property.kt b/test/datagen/kotlin/delegated-property.kt new file mode 100644 index 000000000..489275ea5 --- /dev/null +++ b/test/datagen/kotlin/delegated-property.kt @@ -0,0 +1,5 @@ +package boa.kotlin.test + +class Example { + var p: String by Delegate() +} \ No newline at end of file diff --git a/test/datagen/kotlin/delegated-superclass.json b/test/datagen/kotlin/delegated-superclass.json new file mode 100644 index 000000000..5d291f690 --- /dev/null +++ b/test/datagen/kotlin/delegated-superclass.json @@ -0,0 +1,52 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "CLASS", + "parents": [ + { + "name": "Bar", + "kind": "DELEGATED", + "delegate": { + "kind": "VARACCESS", + "variable": "b" + } + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "b", + "variable_type": { + "name": "Bar", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/delegated-superclass.kt b/test/datagen/kotlin/delegated-superclass.kt new file mode 100644 index 000000000..623bd71d9 --- /dev/null +++ b/test/datagen/kotlin/delegated-superclass.kt @@ -0,0 +1,3 @@ +class Foo(b: Bar): Bar by b { + +} \ No newline at end of file diff --git a/test/datagen/kotlin/do-while.json b/test/datagen/kotlin/do-while.json new file mode 100644 index 000000000..045bfba85 --- /dev/null +++ b/test/datagen/kotlin/do-while.json @@ -0,0 +1,81 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "dowhile", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "DO", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"hi\"" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + }, + { + "kind": "DO", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "EMPTY" + } + ] + } + ], + "conditions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "mutableList" + } + ], + "method": "remove", + "method_args": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} diff --git a/test/datagen/kotlin/do-while.kt b/test/datagen/kotlin/do-while.kt new file mode 100644 index 000000000..1a844a42f --- /dev/null +++ b/test/datagen/kotlin/do-while.kt @@ -0,0 +1,7 @@ +fun dowhile() { + do { + print("hi") + } while (x) + + do while (mutableList.remove(2)) +} diff --git a/test/datagen/kotlin/dynamic-type.json b/test/datagen/kotlin/dynamic-type.json new file mode 100644 index 000000000..f1b0952c6 --- /dev/null +++ b/test/datagen/kotlin/dynamic-type.json @@ -0,0 +1,25 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "variables": [ + { + "name": "dyn", + "variable_type": { + "name": "dynamic", + "kind": "DYNAMIC" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "2" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/dynamic-type.kt b/test/datagen/kotlin/dynamic-type.kt new file mode 100644 index 000000000..2ad4a400f --- /dev/null +++ b/test/datagen/kotlin/dynamic-type.kt @@ -0,0 +1,3 @@ +package boa.kotlin.test + +val dyn: dynamic = 2 \ No newline at end of file diff --git a/test/datagen/kotlin/enum-basic.json b/test/datagen/kotlin/enum-basic.json new file mode 100644 index 000000000..9e9817d45 --- /dev/null +++ b/test/datagen/kotlin/enum-basic.json @@ -0,0 +1,65 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "Test", + "kind": "ENUM", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "OTHER", + "other": "enum" + } + ], + "fields": [ + { + "name": "ONE", + "variable_type": { + "name": "Test", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + }, + { + "name": "TWO", + "variable_type": { + "name": "Test", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + }, + { + "name": "THREE", + "variable_type": { + "name": "Test", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/enum-basic.kt b/test/datagen/kotlin/enum-basic.kt new file mode 100644 index 000000000..a5212df12 --- /dev/null +++ b/test/datagen/kotlin/enum-basic.kt @@ -0,0 +1,7 @@ +package boa.kotlin.test + +private enum class Test { + ONE, + TWO, + private THREE +} diff --git a/test/datagen/kotlin/enum-with-field.json b/test/datagen/kotlin/enum-with-field.json new file mode 100644 index 000000000..8d8c3b1a8 --- /dev/null +++ b/test/datagen/kotlin/enum-with-field.json @@ -0,0 +1,157 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "Color", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "rgb", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "rgb", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "RED", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0xFF0000" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + }, + { + "name": "GREEN", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0x00FF00" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + }, + { + "name": "BLUE", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0x0000FF" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/enum-with-field.kt b/test/datagen/kotlin/enum-with-field.kt new file mode 100644 index 000000000..5348edfd1 --- /dev/null +++ b/test/datagen/kotlin/enum-with-field.kt @@ -0,0 +1,7 @@ +package boa.kotlin.test + +enum class Color(val rgb: Int) { + RED(0xFF0000), + GREEN(0x00FF00), + BLUE(0x0000FF) +} diff --git a/test/datagen/kotlin/enum-with-override.json b/test/datagen/kotlin/enum-with-override.json new file mode 100644 index 000000000..c7924de7a --- /dev/null +++ b/test/datagen/kotlin/enum-with-override.json @@ -0,0 +1,103 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "ProtocolState", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "methods": [ + { + "name": "signal", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ], + "return_type": { + "name": "ProtocolState", + "kind": "OTHER" + } + } + ], + "fields": [ + { + "name": "WAITING", + "variable_type": { + "name": "ProtocolState", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "initializer": { + "kind": "NEW", + "anon_declaration": { + "name": "ProtocolState", + "kind": "ENUM", + "methods": [ + { + "name": "signal", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "TALKING" + } + } + ] + } + } + }, + { + "name": "TALKING", + "variable_type": { + "name": "ProtocolState", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "initializer": { + "kind": "NEW", + "anon_declaration": { + "name": "ProtocolState", + "kind": "ENUM", + "methods": [ + { + "name": "signal", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "WAITING" + } + } + ] + } + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/enum-with-override.kt b/test/datagen/kotlin/enum-with-override.kt new file mode 100644 index 000000000..b51499e47 --- /dev/null +++ b/test/datagen/kotlin/enum-with-override.kt @@ -0,0 +1,13 @@ +package boa.kotlin.test + +enum class ProtocolState { + WAITING { + override fun signal() = TALKING + }, + TALKING { + override fun signal() = WAITING + }; + + abstract fun signal(): ProtocolState + +} diff --git a/test/datagen/kotlin/expressionified-val-var.json b/test/datagen/kotlin/expressionified-val-var.json new file mode 100644 index 000000000..48fd7129a --- /dev/null +++ b/test/datagen/kotlin/expressionified-val-var.json @@ -0,0 +1,146 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "methods": [ + { + "name": "", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "q", + "initializer": { + "kind": "VARACCESS", + "variable": "p" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "w", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "u" + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "q", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "p" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "y" + } + }, + { + "name": "y", + "initializer": { + "kind": "VARACCESS", + "variable": "z" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/expressionified-val-var.kt b/test/datagen/kotlin/expressionified-val-var.kt new file mode 100644 index 000000000..78990520e --- /dev/null +++ b/test/datagen/kotlin/expressionified-val-var.kt @@ -0,0 +1,16 @@ +package boa.kotlin.test + +class C { + val x = y + var y = z + + init { + var q = p + val w = u + } + + fun foo(val x: T) { + val q = p + println(x) + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/extension-property.json b/test/datagen/kotlin/extension-property.json new file mode 100644 index 000000000..78985b7af --- /dev/null +++ b/test/datagen/kotlin/extension-property.json @@ -0,0 +1,147 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo.baz.", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + }, + { + "name": "foo.bar.", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "return_type": { + "name": "String", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"hi\"" + } + ] + } + ] + } + ] + }, + { + "name": "foo.foo.", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "LITERAL", + "literal": "3" + } + }, + { + "name": "foo.foo.", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "return_type": { + "name": "Unit", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo" + } + ], + "variable": "bar" + }, + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo.bad.", + "return_type": { + "name": "String", + "kind": "OTHER" + } + }, + { + "name": "foo.bar.", + "expression": { + "kind": "LITERAL", + "literal": "3" + } + } + ] + } + ] +} diff --git a/test/datagen/kotlin/extension-property.kt b/test/datagen/kotlin/extension-property.kt new file mode 100644 index 000000000..cfd92f4cf --- /dev/null +++ b/test/datagen/kotlin/extension-property.kt @@ -0,0 +1,15 @@ +val foo.baz: Int + get() { return 3 } + +public val foo.bar: Int + private get() : String { return "hi" } + +val foo.foo: Int + get() = 3 + private set(x: Int) { foo.bar = x } + +val foo.bad: String + get + +val foo.bar + get() = 3 diff --git a/test/datagen/kotlin/file-annot.json b/test/datagen/kotlin/file-annot.json new file mode 100644 index 000000000..cdc319517 --- /dev/null +++ b/test/datagen/kotlin/file-annot.json @@ -0,0 +1,135 @@ +{ + "namespaces": [ + { + "name": "kotlinx.ast.common", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "annotation_values": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + }, + { + "kind": "LITERAL", + "literal": "\"Foo\"" + } + ] + }, + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "g" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ], + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "\"Foo\"" + }, + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "g" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ], + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "annotation_values": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + }, + { + "kind": "LITERAL", + "literal": "\"Foo\"" + } + ] + }, + { + "kind": "LITERAL", + "literal": "3" + } + ], + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "\"Foo\"" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ], + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "\"Foo\"" + } + ], + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "other": "file" + } + ], + "declarations": [ + { + "name": "C", + "kind": "CLASS" + } + ], + "imports": [ + "java.util.List" + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/file-annot.kt b/test/datagen/kotlin/file-annot.kt new file mode 100644 index 000000000..c7e00ad3d --- /dev/null +++ b/test/datagen/kotlin/file-annot.kt @@ -0,0 +1,12 @@ +@file:JvmName(f = "Foo", g = 3) +@file:JvmName("Foo", g = 3) +@file:JvmName(f = "Foo", 3) +@file:JvmName("Foo", 3) +@file:JvmName("Foo") +@file:JvmName() +@file:JvmName +package kotlinx.ast.common + +import java.util.List + +class C {} diff --git a/test/datagen/kotlin/file-annot2.json b/test/datagen/kotlin/file-annot2.json new file mode 100644 index 000000000..2af5ddb1e --- /dev/null +++ b/test/datagen/kotlin/file-annot2.json @@ -0,0 +1,99 @@ +{ + "namespaces": [ + { + "name": "", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "annotation_values": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + }, + { + "kind": "LITERAL", + "literal": "\"Foo\"" + } + ] + }, + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "g" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ], + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "\"Foo\"" + }, + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "g" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ], + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "JvmName", + "annotation_values": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + }, + { + "kind": "LITERAL", + "literal": "\"Foo\"" + } + ] + }, + { + "kind": "LITERAL", + "literal": "3" + } + ], + "other": "file" + } + ], + "declarations": [ + { + "name": "C", + "kind": "CLASS" + } + ], + "imports": [ + "java.util.List" + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/file-annot2.kt b/test/datagen/kotlin/file-annot2.kt new file mode 100644 index 000000000..564e29475 --- /dev/null +++ b/test/datagen/kotlin/file-annot2.kt @@ -0,0 +1,4 @@ +@file:[JvmName(f = "Foo", g = 3) JvmName("Foo", g = 3) JvmName(f = "Foo", 3)] +import java.util.List + +class C {} diff --git a/test/datagen/kotlin/for-loop-label.json b/test/datagen/kotlin/for-loop-label.json new file mode 100644 index 000000000..2080f7120 --- /dev/null +++ b/test/datagen/kotlin/for-loop-label.json @@ -0,0 +1,98 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "methods": [ + { + "name": "foo", + "arguments": [ + { + "name": "things", + "variable_type": { + "name": "List", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "loop" + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "thing" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "VARACCESS", + "variable": "things" + } + ], + "variable_declarations": [ + { + "name": "thing", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/for-loop-label.kt b/test/datagen/kotlin/for-loop-label.kt new file mode 100644 index 000000000..f52477f62 --- /dev/null +++ b/test/datagen/kotlin/for-loop-label.kt @@ -0,0 +1,7 @@ +package boa.kotlin.test + +fun foo(things: List) { + loop@ for(thing: String in things) { + println(thing) + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/for-loop.json b/test/datagen/kotlin/for-loop.json new file mode 100644 index 000000000..fbf8a9682 --- /dev/null +++ b/test/datagen/kotlin/for-loop.json @@ -0,0 +1,331 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "Six", + "kind": "CLASS", + "methods": [ + { + "name": "foo", + "arguments": [ + { + "name": "things", + "variable_type": { + "name": "List", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "thing" + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "VARACCESS", + "variable": "things" + } + ], + "variable_declarations": [ + { + "name": "thing", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK" + } + ], + "initializations": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "array" + } + ], + "method": "withIndex" + } + ], + "variable_declarations": [ + { + "name": "index", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "value", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "bar", + "arguments": [ + { + "name": "things", + "variable_type": { + "name": "List", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + }, + { + "kind": "VARACCESS", + "variable": "thing" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "things" + } + ], + "method": "withIndex" + } + ], + "variable_declarations": [ + { + "name": "index", + "variable_type": { + "name": "int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "value", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "baz", + "arguments": [ + { + "name": "things", + "variable_type": { + "name": "List", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "thing" + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "VARACCESS", + "variable": "things" + } + ], + "variable_declarations": [ + { + "name": "thing", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "EMPTY" + } + ] + } + ], + "initializations": [ + { + "kind": "VARACCESS", + "variable": "iterator" + } + ], + "variable_declarations": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/for-loop.kt b/test/datagen/kotlin/for-loop.kt new file mode 100644 index 000000000..a8546afb2 --- /dev/null +++ b/test/datagen/kotlin/for-loop.kt @@ -0,0 +1,20 @@ +package boa.kotlin.test + +class Six { + fun foo(things: List) { + for (thing: String in things) + println(thing) + for ((index, value) in array.withIndex()) { + } + } + fun bar(things: List) { + for ((index: int, value: String) in things.withIndex()) { + println(index, thing) + } + } + fun baz(things: List) { + for (thing: String in things) + println(thing) + for (x in iterator); + } +} diff --git a/test/datagen/kotlin/func-expr-throws.json b/test/datagen/kotlin/func-expr-throws.json new file mode 100644 index 000000000..b02ca4d0b --- /dev/null +++ b/test/datagen/kotlin/func-expr-throws.json @@ -0,0 +1,42 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "TracksContentProvider", + "kind": "CLASS", + "methods": [ + { + "name": "delete", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "UnsupportedOperationException", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"Not yet implemented\"" + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] +} diff --git a/test/datagen/kotlin/func-expr-throws.kt b/test/datagen/kotlin/func-expr-throws.kt new file mode 100644 index 000000000..3fea84a83 --- /dev/null +++ b/test/datagen/kotlin/func-expr-throws.kt @@ -0,0 +1,3 @@ +class TracksContentProvider { + fun delete(): Int = throw UnsupportedOperationException("Not yet implemented") +} diff --git a/test/datagen/kotlin/function-def.json b/test/datagen/kotlin/function-def.json new file mode 100644 index 000000000..d63c57f46 --- /dev/null +++ b/test/datagen/kotlin/function-def.json @@ -0,0 +1,58 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "name": "f2", + "expression": { + "kind": "LITERAL", + "literal": "1" + } + }, + { + "name": "f3", + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/function-def.kt b/test/datagen/kotlin/function-def.kt new file mode 100644 index 000000000..cc5801c5c --- /dev/null +++ b/test/datagen/kotlin/function-def.kt @@ -0,0 +1,9 @@ +fun f() { + return 1; +} + +fun f2() = 1; + +fun f3() = { + return 1; +} diff --git a/test/datagen/kotlin/function-return.json b/test/datagen/kotlin/function-return.json new file mode 100644 index 000000000..b27361d06 --- /dev/null +++ b/test/datagen/kotlin/function-return.json @@ -0,0 +1,98 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "methods": [ + { + "name": "factorial", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "OP_MULT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "METHODCALL", + "method": "factorial", + "method_args": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LTEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/function-return.kt b/test/datagen/kotlin/function-return.kt new file mode 100644 index 000000000..3a2f6041e --- /dev/null +++ b/test/datagen/kotlin/function-return.kt @@ -0,0 +1,6 @@ +package boa.kotlin.test + +fun factorial(x: Int) { + if (x <= 1) return 1 + else return x * factorial(x - 1) +} \ No newline at end of file diff --git a/test/datagen/kotlin/functioncall.json b/test/datagen/kotlin/functioncall.json new file mode 100644 index 000000000..28a6e8633 --- /dev/null +++ b/test/datagen/kotlin/functioncall.json @@ -0,0 +1,64 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "variables": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "foo", + "method_args": [ + { + "kind": "LITERAL", + "literal": "3" + }, + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "4" + } + ] + } + ] + } + }, + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "method": "bar", + "method_args": [ + { + "kind": "LITERAL", + "literal": "7" + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/functioncall.kt b/test/datagen/kotlin/functioncall.kt new file mode 100644 index 000000000..f1ea2bf1a --- /dev/null +++ b/test/datagen/kotlin/functioncall.kt @@ -0,0 +1,5 @@ +package boa.kotlin.test + +val x = foo(3, x = 4) + +val y = x.bar(7) diff --git a/test/datagen/kotlin/generic-func.json b/test/datagen/kotlin/generic-func.json new file mode 100644 index 000000000..cb16cae7d --- /dev/null +++ b/test/datagen/kotlin/generic-func.json @@ -0,0 +1,137 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "v", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "v" + }, + { + "kind": "VARACCESS", + "variable": "v" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "f2", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "expected", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "properties" + } + ], + "method": "map", + "method_args": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "generic_parameters": [ + { + "name": "*", + "kind": "GENERIC" + } + ], + "variable": "KCallable" + } + ], + "method": "name" + } + ] + } + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "Int", + "kind": "GENERIC" + } + ], + "method": "f", + "method_args": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} diff --git a/test/datagen/kotlin/generic-func.kt b/test/datagen/kotlin/generic-func.kt new file mode 100644 index 000000000..515e829d9 --- /dev/null +++ b/test/datagen/kotlin/generic-func.kt @@ -0,0 +1,8 @@ +fun f(v: T) { + return v + v +} + +fun f2() { + val expected = properties.map(KCallable<*>::name) + return f(3); +} diff --git a/test/datagen/kotlin/generic-klass.json b/test/datagen/kotlin/generic-klass.json new file mode 100644 index 000000000..7b755a32d --- /dev/null +++ b/test/datagen/kotlin/generic-klass.json @@ -0,0 +1,37 @@ +{ + "namespaces": [ + { + "name": "Foo", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "D", + "kind": "GENERIC" + }, + { + "name": "T : S", + "kind": "GENERIC" + }, + { + "name": "F", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "O", + "kind": "CLASS" + }, + { + "name": "P", + "kind": "CLASS" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/generic-klass.kt b/test/datagen/kotlin/generic-klass.kt new file mode 100644 index 000000000..fb9065743 --- /dev/null +++ b/test/datagen/kotlin/generic-klass.kt @@ -0,0 +1,4 @@ +package Foo + +class C : O, P { +} diff --git a/test/datagen/kotlin/if-then-else.json b/test/datagen/kotlin/if-then-else.json new file mode 100644 index 000000000..fee8cd0ed --- /dev/null +++ b/test/datagen/kotlin/if-then-else.json @@ -0,0 +1,126 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"Other!\"" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/if-then-else.kt b/test/datagen/kotlin/if-then-else.kt new file mode 100644 index 000000000..f6f9c63fe --- /dev/null +++ b/test/datagen/kotlin/if-then-else.kt @@ -0,0 +1,13 @@ +package boa.kotlin.test + +class C { + fun foo() { + if (x == 2) { + println(2) + } else if (x == 3) { + println(3) + } else { + println("Other!") + } + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/ifs.json b/test/datagen/kotlin/ifs.json new file mode 100644 index 000000000..e65f970ec --- /dev/null +++ b/test/datagen/kotlin/ifs.json @@ -0,0 +1,838 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "asStmt", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "xEE" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "xEE" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "xBE" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "xBE" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "xEB" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "xEB" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "xBB" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "xBB" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "EMPTY" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "xNoT" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "xNoF" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "EMPTY" + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "asArgument", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "CoNLLStats", + "method_args": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "precision" + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_DIV", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "correctDouble" + }, + { + "kind": "VARACCESS", + "variable": "outputTotal" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "0.0" + } + ] + } + ], + "conditions": [ + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "outputTotal" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "recall" + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_DIV", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "correctDouble" + }, + { + "kind": "VARACCESS", + "variable": "goldTotal" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "0.0" + } + ] + } + ], + "conditions": [ + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "goldTotal" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f1Score" + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_DIV", + "expressions": [ + { + "kind": "OP_MULT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + }, + { + "kind": "VARACCESS", + "variable": "correctDouble" + } + ] + }, + { + "kind": "PAREN", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "outputTotal" + }, + { + "kind": "VARACCESS", + "variable": "goldTotal" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "0.0" + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_AND", + "expressions": [ + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "outputTotal" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + }, + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "goldTotal" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "3" + } + }, + { + "name": "xEE", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + } + }, + { + "name": "xEB", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + } + }, + { + "name": "xBE", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + } + }, + { + "name": "xBB", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + } + } + ] + } + ] +} diff --git a/test/datagen/kotlin/ifs.kt b/test/datagen/kotlin/ifs.kt new file mode 100644 index 000000000..66c254c66 --- /dev/null +++ b/test/datagen/kotlin/ifs.kt @@ -0,0 +1,44 @@ +val y = 3 +val xEE = if (y == 3) 1 else 2 +val xEB = if (y == 3) 1 else { 2 } +val xBE = if (y == 3) { 1 } else 2 +val xBB = if (y == 3) { 1 } else { 2 } + +fun asStmt() { + if (y == 3) + xEE = 1 + else + xEE = 2 + if (y == 3) { + xBE = 1 + } else + xBE = 2 + if (y == 3) + xEB = 1 + else { + xEB = 2 + } + if (y == 3) { + xBB = 1 + } else { + xBB = 2 + } + + if (y == 3) + ; + else + xNoT = 2 + + if (y == 3) + xNoF = 1 + else + ; +} + +fun asArgument() { + CoNLLStats( + precision = if (outputTotal > 0) correctDouble / outputTotal else 0.0, + recall = if (goldTotal > 0) correctDouble / goldTotal else 0.0, + f1Score = if (outputTotal > 0 && goldTotal > 0) 2 * correctDouble / (outputTotal + goldTotal) else 0.0 + ) +} diff --git a/test/datagen/kotlin/imports.json b/test/datagen/kotlin/imports.json new file mode 100644 index 000000000..95fb17ac4 --- /dev/null +++ b/test/datagen/kotlin/imports.json @@ -0,0 +1,18 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "C", + "kind": "CLASS" + } + ], + "imports": [ + "java.util.List", + "java.io.*", + "jave.io.File as F" + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/imports.kt b/test/datagen/kotlin/imports.kt new file mode 100644 index 000000000..ca2849121 --- /dev/null +++ b/test/datagen/kotlin/imports.kt @@ -0,0 +1,5 @@ +import java.util.List +import java.io.* +import jave.io.File as F + +class C {} diff --git a/test/datagen/kotlin/inc-dec.json b/test/datagen/kotlin/inc-dec.json new file mode 100644 index 000000000..a5959cbe4 --- /dev/null +++ b/test/datagen/kotlin/inc-dec.json @@ -0,0 +1,105 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_DEC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "is_postfix": true + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_INC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "is_postfix": true + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_DEC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_INC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "LITERAL", + "literal": "7" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/inc-dec.kt b/test/datagen/kotlin/inc-dec.kt new file mode 100644 index 000000000..3b61fec32 --- /dev/null +++ b/test/datagen/kotlin/inc-dec.kt @@ -0,0 +1,10 @@ +package boa.kotlin.test + +fun foo() { + x-- + x++ + --x + ++x + ! x + -7 +} \ No newline at end of file diff --git a/test/datagen/kotlin/inner-class.json b/test/datagen/kotlin/inner-class.json new file mode 100644 index 000000000..d2d6d613e --- /dev/null +++ b/test/datagen/kotlin/inner-class.json @@ -0,0 +1,76 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Outer", + "kind": "CLASS", + "fields": [ + { + "name": "bar", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "1" + } + } + ], + "nested_declarations": [ + { + "name": "Nested", + "kind": "CLASS", + "methods": [ + { + "name": "foo", + "expression": { + "kind": "LITERAL", + "literal": "2" + } + } + ] + } + ] + } + ], + "variables": [ + { + "name": "demo", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Outer" + } + ], + "method": "Nested" + } + ], + "method": "foo" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/inner-class.kt b/test/datagen/kotlin/inner-class.kt new file mode 100644 index 000000000..c752eccf0 --- /dev/null +++ b/test/datagen/kotlin/inner-class.kt @@ -0,0 +1,8 @@ +class Outer { + private val bar: Int = 1 + class Nested { + fun foo() = 2 + } +} + +val demo = Outer.Nested().foo() // == 2 diff --git a/test/datagen/kotlin/inner-interface.json b/test/datagen/kotlin/inner-interface.json new file mode 100644 index 000000000..fa186ce84 --- /dev/null +++ b/test/datagen/kotlin/inner-interface.json @@ -0,0 +1,37 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "OuterInterface", + "kind": "INTERFACE", + "nested_declarations": [ + { + "name": "InnerClass", + "kind": "CLASS" + }, + { + "name": "InnerInterface", + "kind": "INTERFACE" + } + ] + }, + { + "name": "OuterClass", + "kind": "CLASS", + "nested_declarations": [ + { + "name": "InnerClass", + "kind": "CLASS" + }, + { + "name": "InnerInterface", + "kind": "INTERFACE" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/inner-interface.kt b/test/datagen/kotlin/inner-interface.kt new file mode 100644 index 000000000..151b10dae --- /dev/null +++ b/test/datagen/kotlin/inner-interface.kt @@ -0,0 +1,9 @@ +interface OuterInterface { + class InnerClass + interface InnerInterface +} + +class OuterClass { + class InnerClass + interface InnerInterface +} diff --git a/test/datagen/kotlin/inner-keyword.json b/test/datagen/kotlin/inner-keyword.json new file mode 100644 index 000000000..cd8dff99c --- /dev/null +++ b/test/datagen/kotlin/inner-keyword.json @@ -0,0 +1,82 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Outer", + "kind": "CLASS", + "fields": [ + { + "name": "bar", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "1" + } + } + ], + "nested_declarations": [ + { + "name": "Inner", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "inner" + } + ], + "methods": [ + { + "name": "foo", + "expression": { + "kind": "VARACCESS", + "variable": "bar" + } + } + ] + } + ] + } + ], + "variables": [ + { + "name": "demo", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "method": "Outer" + } + ], + "method": "Inner" + } + ], + "method": "foo" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/inner-keyword.kt b/test/datagen/kotlin/inner-keyword.kt new file mode 100644 index 000000000..75d2637a3 --- /dev/null +++ b/test/datagen/kotlin/inner-keyword.kt @@ -0,0 +1,8 @@ +class Outer { + private val bar: Int = 1 + inner class Inner { + fun foo() = bar + } +} + +val demo = Outer().Inner().foo() // == 1 diff --git a/test/datagen/kotlin/inout-generic.json b/test/datagen/kotlin/inout-generic.json new file mode 100644 index 000000000..e193a6da9 --- /dev/null +++ b/test/datagen/kotlin/inout-generic.json @@ -0,0 +1,48 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "out T", + "kind": "GENERIC" + }, + { + "name": "in S", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "m", + "generic_parameters": [ + { + "name": "out Q", + "kind": "GENERIC" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ], + "variables": [ + { + "name": "x", + "variable_type": { + "name": "String", + "kind": "OTHER" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/inout-generic.kt b/test/datagen/kotlin/inout-generic.kt new file mode 100644 index 000000000..7dc121301 --- /dev/null +++ b/test/datagen/kotlin/inout-generic.kt @@ -0,0 +1,5 @@ +var x: String + +class C { + fun m() {} +} diff --git a/test/datagen/kotlin/int-to-day.json b/test/datagen/kotlin/int-to-day.json new file mode 100644 index 000000000..e99282cab --- /dev/null +++ b/test/datagen/kotlin/int-to-day.json @@ -0,0 +1,285 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "methods": [ + { + "name": "numberToDay", + "arguments": [ + { + "name": "day", + "variable_type": { + "name": "int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"Monday\"" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"Tuesday\"" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"Wednesday\"" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "4" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"Thursday\"" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "5" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"Friday\"" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "6" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"Saturday\"" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "7" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"Sunday\"" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "0" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"Sunday\"" + } + ] + }, + { + "kind": "DEFAULT" + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"Invalid day.\"" + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "day" + } + ] + } + ] + } + ] + }, + { + "name": "isValidDayNumber", + "arguments": [ + { + "name": "day", + "variable_type": { + "name": "int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "IN", + "expressions": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "7" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "true" + } + ] + }, + { + "kind": "DEFAULT" + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "false" + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "day" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/int-to-day.kt b/test/datagen/kotlin/int-to-day.kt new file mode 100644 index 000000000..bc6684dcd --- /dev/null +++ b/test/datagen/kotlin/int-to-day.kt @@ -0,0 +1,22 @@ +package boa.kotlin.test + +fun numberToDay (day: int) { + when (day) { + 1 -> "Monday" + 2 -> "Tuesday" + 3 -> "Wednesday" + 4 -> "Thursday" + 5 -> "Friday" + 6 -> "Saturday" + 7 -> "Sunday" + 0 -> "Sunday" + else -> "Invalid day." + } +} + +fun isValidDayNumber(day: int) { + when (day) { + in 1..7 -> true + else -> false + } +} diff --git a/test/datagen/kotlin/klass-with-import.json b/test/datagen/kotlin/klass-with-import.json new file mode 100644 index 000000000..4154f9ff7 --- /dev/null +++ b/test/datagen/kotlin/klass-with-import.json @@ -0,0 +1,16 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "C", + "kind": "CLASS" + } + ], + "imports": [ + "java.util.List" + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/klass-with-import.kt b/test/datagen/kotlin/klass-with-import.kt new file mode 100644 index 000000000..c8278aaaf --- /dev/null +++ b/test/datagen/kotlin/klass-with-import.kt @@ -0,0 +1,6 @@ +package boa.kotlin.test + +import java.util.List + +class C { +} diff --git a/test/datagen/kotlin/klass-with-val-field.json b/test/datagen/kotlin/klass-with-val-field.json new file mode 100644 index 000000000..3bb93553e --- /dev/null +++ b/test/datagen/kotlin/klass-with-val-field.json @@ -0,0 +1,43 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "fields": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "3" + } + }, + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "5" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/klass-with-val-field.kt b/test/datagen/kotlin/klass-with-val-field.kt new file mode 100644 index 000000000..73d71ca91 --- /dev/null +++ b/test/datagen/kotlin/klass-with-val-field.kt @@ -0,0 +1,6 @@ +package boa.kotlin.test + +class C { + val x: Int = 3 + val y = 5 +} diff --git a/test/datagen/kotlin/klass-with-var-field.json b/test/datagen/kotlin/klass-with-var-field.json new file mode 100644 index 000000000..9fc2cf6c6 --- /dev/null +++ b/test/datagen/kotlin/klass-with-var-field.json @@ -0,0 +1,33 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "fields": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "initializer": { + "kind": "LITERAL", + "literal": "3" + } + }, + { + "name": "y", + "initializer": { + "kind": "LITERAL", + "literal": "5" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/klass-with-var-field.kt b/test/datagen/kotlin/klass-with-var-field.kt new file mode 100644 index 000000000..5f350d53c --- /dev/null +++ b/test/datagen/kotlin/klass-with-var-field.kt @@ -0,0 +1,6 @@ +package boa.kotlin.test + +class C { + var x: Int = 3 + var y = 5 +} diff --git a/test/datagen/kotlin/klass1.json b/test/datagen/kotlin/klass1.json new file mode 100644 index 000000000..5005e9944 --- /dev/null +++ b/test/datagen/kotlin/klass1.json @@ -0,0 +1,13 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "C", + "kind": "CLASS" + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/klass1.kt b/test/datagen/kotlin/klass1.kt new file mode 100644 index 000000000..86aa66e75 --- /dev/null +++ b/test/datagen/kotlin/klass1.kt @@ -0,0 +1,4 @@ +package boa.kotlin.test + +class C { +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/AnonymousInitializer.json b/test/datagen/kotlin/kotlin-compiler-tests/AnonymousInitializer.json new file mode 100644 index 000000000..8fa0e6944 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/AnonymousInitializer.json @@ -0,0 +1,57 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "CLASS", + "methods": [ + { + "name": "", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "c", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "f" + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/AnonymousInitializer.kt b/test/datagen/kotlin/kotlin-compiler-tests/AnonymousInitializer.kt new file mode 100644 index 000000000..a94df5e5b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/AnonymousInitializer.kt @@ -0,0 +1,9 @@ +class Foo { + + init { + foo() + val c = f + } + +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/BabySteps.json b/test/datagen/kotlin/kotlin-compiler-tests/BabySteps.json new file mode 100644 index 000000000..54fd6e7c5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/BabySteps.json @@ -0,0 +1,104 @@ +{ + "namespaces": [ + { + "name": "foo", + "declarations": [ + { + "name": "Runnable", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "a", + "kind": "GENERIC" + }, + { + "name": "a", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "foo", + "kind": "CLASS" + }, + { + "name": "bar", + "kind": "DELEGATED", + "delegate": { + "kind": "VARACCESS", + "variable": "x" + } + }, + { + "name": "bar", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "doo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "0" + } + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "foo", + "method_args": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "d" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/BabySteps.kt b/test/datagen/kotlin/kotlin-compiler-tests/BabySteps.kt new file mode 100644 index 000000000..cf99c2a57 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/BabySteps.kt @@ -0,0 +1,5 @@ +package foo + +class Runnable(a : doo = 0) : foo(d=0), bar by x, bar { + +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ByClauses.json b/test/datagen/kotlin/kotlin-compiler-tests/ByClauses.json new file mode 100644 index 000000000..fa9d91bbd --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ByClauses.json @@ -0,0 +1,314 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "parents": [ + { + "name": "b", + "kind": "DELEGATED", + "delegate": { + "kind": "VARACCESS", + "variable": "a" + } + } + ], + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + } + ] + }, + { + "name": "A", + "kind": "CLASS", + "parents": [ + { + "name": "b", + "kind": "DELEGATED", + "delegate": { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "OP_MULT", + "expressions": [ + { + "kind": "METHODCALL", + "method": "b" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + } + } + ], + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + } + ] + }, + { + "name": "A", + "kind": "CLASS", + "parents": [ + { + "name": "b", + "kind": "DELEGATED", + "delegate": { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + } + ], + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + } + ] + }, + { + "name": "A", + "kind": "CLASS", + "parents": [ + { + "name": "b", + "kind": "DELEGATED", + "delegate": { + "kind": "PAREN", + "expressions": [ + { + "kind": "METHODCALL", + "method": "a", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + } + } + ], + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + } + ] + }, + { + "name": "A", + "kind": "CLASS", + "parents": [ + { + "name": "b", + "kind": "DELEGATED", + "delegate": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "METHODCALL", + "method": "a", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + } + } + ], + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + } + ] + }, + { + "name": "A", + "kind": "CLASS", + "parents": [ + { + "name": "b", + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "a", + "method_args": [ + { + "kind": "METHODCALL", + "method": "a", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + } + } + ], + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + } + ] + }, + { + "name": "A", + "kind": "CLASS", + "parents": [ + { + "name": "b", + "kind": "DELEGATED", + "delegate": { + "kind": "NEW", + "anon_declaration": { + "name": "", + "kind": "SINGLETON", + "methods": [ + { + "name": "f", + "expression": { + "kind": "METHODCALL", + "method": "a", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + } + ] + } + } + } + ], + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ByClauses.kt b/test/datagen/kotlin/kotlin-compiler-tests/ByClauses.kt new file mode 100644 index 000000000..b67905fa5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ByClauses.kt @@ -0,0 +1,23 @@ +class A : b by a { + companion object {} +} +class A : b by a + b() * 5 { + companion object {} +} +class A : b by (a) { + companion object {} +} +class A : b by (a {}) { + companion object {} +} +class A : b by a[a {}] { + companion object {} +} +class A : b by a(a {}) { + companion object {} +} +class A : b by object { + fun f() = a {} +} { + companion object {} +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/CallWithManyClosures.json b/test/datagen/kotlin/kotlin-compiler-tests/CallWithManyClosures.json new file mode 100644 index 000000000..a58e3c4bb --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/CallWithManyClosures.json @@ -0,0 +1,283 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "f", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "f", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "f", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "f", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + } + ] + } + ], + "method": "", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + } + ] + } + ], + "method": "", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + } + ] + } + ], + "generic_parameters": [ + { + "name": "A", + "kind": "GENERIC" + } + ], + "method": "", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/CallWithManyClosures.kt b/test/datagen/kotlin/kotlin-compiler-tests/CallWithManyClosures.kt new file mode 100644 index 000000000..6418e2bad --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/CallWithManyClosures.kt @@ -0,0 +1,7 @@ +val a = f() {} {} {} +val a = f {} {} {} +val a = f {} +val a = f() {} +val a = (f) {} {} {} +val a = (f)() {} {} {} +val a = (f)() {} {} {} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/CallsInWhen.json b/test/datagen/kotlin/kotlin-compiler-tests/CallsInWhen.json new file mode 100644 index 000000000..d849666a8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/CallsInWhen.json @@ -0,0 +1,324 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "variable": "foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "method": "foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "method": "foo", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "method": "foo", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "VARACCESS", + "variable": "d" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LAMBDA", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "bar" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LAMBDA", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "bar" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LAMBDA", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "bar" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "DEFAULT" + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/CallsInWhen.kt b/test/datagen/kotlin/kotlin-compiler-tests/CallsInWhen.kt new file mode 100644 index 000000000..daf2ea472 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/CallsInWhen.kt @@ -0,0 +1,15 @@ +fun foo() { + when (a) { + a.foo -> a + a.foo() -> a + a.foo -> a + a.foo(a) -> a + a.foo(a, d) -> a + a.{bar} -> a + a.{!bar} -> a + a.{ -> !bar} -> a + else -> a + } +} + + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/CollectionLiterals.json b/test/datagen/kotlin/kotlin-compiler-tests/CollectionLiterals.json new file mode 100644 index 000000000..7bcdea7b5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/CollectionLiterals.json @@ -0,0 +1,192 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "test", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYINIT" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "ARRAYINIT" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "ARRAYINIT" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "ARRAYINIT" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "ARRAYINIT" + }, + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "ARRAYINIT" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/CollectionLiterals.kt b/test/datagen/kotlin/kotlin-compiler-tests/CollectionLiterals.kt new file mode 100644 index 000000000..6f9888359 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/CollectionLiterals.kt @@ -0,0 +1,14 @@ +fun test() { + [] + [1] + [1, 2] + [[]] + [[1]] + [1, []] + [[], 1] + [[], [1, []]] + [1, + 2] + [1, + [2]] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Constructors.json b/test/datagen/kotlin/kotlin-compiler-tests/Constructors.json new file mode 100644 index 000000000..3786dd2be --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Constructors.json @@ -0,0 +1,141 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "foo", + "kind": "CLASS" + }, + { + "name": "foo", + "kind": "CLASS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + } + ], + "parents": [ + { + "name": "Bar", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ] + } + ] + }, + { + "name": "foo", + "kind": "CLASS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + } + ], + "parents": [ + { + "name": "Bar", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + } + ] + }, + { + "name": "foo", + "kind": "CLASS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "Bar", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ] + } + ] + }, + { + "name": "foo", + "kind": "CLASS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "Bar", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Constructors.kt b/test/datagen/kotlin/kotlin-compiler-tests/Constructors.kt new file mode 100644 index 000000000..c48aecd97 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Constructors.kt @@ -0,0 +1,7 @@ +class foo { +} + +public class foo() : Bar +protected class foo private () : Bar +private class foo() : Bar +internal class foo private () : Bar \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/DefinitelyNotNullType.json b/test/datagen/kotlin/kotlin-compiler-tests/DefinitelyNotNullType.json new file mode 100644 index 000000000..9d6d633dc --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/DefinitelyNotNullType.json @@ -0,0 +1,209 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo1", + "return_type": { + "name": "T!!", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "T!!", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "List", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "z", + "variable_type": { + "name": "T!!.(T!!) -> T!!", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo2", + "return_type": { + "name": "T!!", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "T!!?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "List", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "z", + "variable_type": { + "name": "T!!?.(T!!?) -> T!!?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "w", + "variable_type": { + "name": "String!!", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo3", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK" + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + } + ] + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "RetentionSourceAndTargetExpression" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/DefinitelyNotNullType.kt b/test/datagen/kotlin/kotlin-compiler-tests/DefinitelyNotNullType.kt new file mode 100644 index 000000000..e160b2821 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/DefinitelyNotNullType.kt @@ -0,0 +1,9 @@ + +fun foo1(x: T!!, y: List, z: T!!.(T!!) -> T!!): T!! {} + +// should be prohibited on type-resolution level +fun foo2(x: T!!?, y: List, z: T!!?.(T!!?) -> T!!?, w: String!!): T!! {} + +fun foo3() { + if (@RetentionSourceAndTargetExpression !!(x == y)) {} +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/DoubleColon.json b/test/datagen/kotlin/kotlin-compiler-tests/DoubleColon.json new file mode 100644 index 000000000..acce33869 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/DoubleColon.json @@ -0,0 +1,976 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "simple", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "A" + } + ], + "method": "a" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "A" + } + ], + "method": "a" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "generic_parameters": [ + { + "name": "String", + "kind": "GENERIC" + }, + { + "name": "Int", + "kind": "GENERIC" + } + ], + "variable": "Map" + } + ], + "method": "size" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "method": "a" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "variable": "b" + } + ], + "method": "c" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "b" + } + ], + "variable": "c" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "variable": "b" + } + ], + "method": "c" + } + ], + "variable": "d" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "b" + } + ] + } + ], + "method": "" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ], + "method": "c" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "" + } + ] + } + ] + } + ] + }, + { + "name": "genericType", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "generic_parameters": [ + { + "name": "b", + "kind": "GENERIC" + } + ], + "variable": "a" + } + ], + "method": "c" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "generic_parameters": [ + { + "name": "b", + "kind": "GENERIC" + } + ], + "variable": "a" + } + ], + "method": "c" + } + ], + "variable": "d" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "generic_parameters": [ + { + "name": "c", + "kind": "GENERIC" + } + ], + "method": "b" + } + ], + "method": "d" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "generic_parameters": [ + { + "name": "c", + "kind": "GENERIC" + } + ], + "method": "b" + } + ], + "method": "d" + } + ], + "variable": "e" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "generic_parameters": [ + { + "name": "c.d", + "kind": "GENERIC" + } + ], + "method": "b" + } + ], + "method": "e" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "generic_parameters": [ + { + "name": "c.d", + "kind": "GENERIC" + } + ], + "method": "b" + } + ], + "method": "e" + } + ], + "variable": "d" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "generic_parameters": [ + { + "name": "c.d", + "kind": "GENERIC" + } + ], + "method": "b" + } + ], + "method": "g" + } + ], + "variable": "h" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "variable": "b" + } + ], + "generic_parameters": [ + { + "name": "d", + "kind": "GENERIC" + } + ], + "method": "c" + } + ], + "generic_parameters": [ + { + "name": "f", + "kind": "GENERIC" + } + ], + "method": "e" + } + ], + "variable": "g" + } + ], + "method": "h" + } + ] + } + ] + } + ] + }, + { + "name": "nullableType", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a?" + } + ], + "method": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a??" + } + ], + "method": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "generic_parameters": [ + { + "name": "b", + "kind": "GENERIC" + } + ], + "variable": "a?" + } + ], + "method": "c" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "generic_parameters": [ + { + "name": "b?", + "kind": "GENERIC" + }, + { + "name": "c?", + "kind": "GENERIC" + } + ], + "variable": "a?" + } + ], + "method": "d" + } + ] + } + ] + } + ] + }, + { + "name": "classLiteral", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "A" + } + ], + "method": "A::class" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "b", + "kind": "GENERIC" + }, + { + "name": "c", + "kind": "GENERIC" + } + ], + "method": "a" + } + ], + "method": "a::class" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "method": "::class" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OTHER", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "METHOD_REFERENCE", + "method": "::class" + } + ], + "literal": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + } + ], + "method": "this::class" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "super" + } + ], + "method": "super::class" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "METHODCALL", + "method": "X" + } + ], + "method": "X()::class" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "NEW", + "anon_declaration": { + "name": "", + "kind": "SINGLETON" + } + } + ], + "method": "object {}::class" + } + ] + } + ] + } + ] + }, + { + "name": "expressions", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this@x" + } + ], + "method": "foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "super@b" + } + ], + "method": "foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "b" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_INC", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "b" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ], + "method": "c" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + ] + } + ], + "method": "c" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "METHODCALL", + "method": "x" + } + ], + "method": "e" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "method": "x" + } + ], + "method": "y" + } + ], + "method": "z" + } + ], + "method": "e" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "b" + } + ], + "variable": "c" + } + ], + "method": "d" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "A" + } + ], + "method": "a" + } + ], + "method": "b" + } + ] + } + ] + } + ] + }, + { + "name": "emptyLHS", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "method": "x" + } + ], + "variable": "name" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "foo", + "method_args": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "method": "x" + } + ], + "variable": "name" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/DoubleColon.kt b/test/datagen/kotlin/kotlin-compiler-tests/DoubleColon.kt new file mode 100644 index 000000000..901f6f353 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/DoubleColon.kt @@ -0,0 +1,65 @@ +fun simple() { + A::a + A::a + 1 + Map::size + + ::a + + a.b::c + a::b.c + a.b::c.d + + (a::b)() + a.(b::c)() +} + +fun genericType() { + a::c + a::c.d + a.b::d + a.b::d.e + a.b::e + a.b::e.d + a.b>::g.h + + a.b.c.e.g::h +} + +fun nullableType() { + a?::b + a??::b + a?::c + a?::d +} + +fun classLiteral() { + A::class + a::class + ::class + a b ::class + + this::class + super::class + X()::class + object {}::class +} + +fun expressions() { + this@x::foo + super@b::foo + + -a::b + ++a::b + a+b::c + (a+b)::c + x()::e + x().y().z()::e + + a::b.c::d + A::a::b +} + +fun emptyLHS() { + ::x.name + foo(::x.name) +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/DoubleColonWhitespaces.json b/test/datagen/kotlin/kotlin-compiler-tests/DoubleColonWhitespaces.json new file mode 100644 index 000000000..301bca814 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/DoubleColonWhitespaces.json @@ -0,0 +1,179 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "tests", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a?" + } + ], + "method": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a?" + } + ], + "method": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a?" + } + ], + "method": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a?" + } + ], + "method": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a?" + } + ], + "method": "b" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a??" + } + ], + "method": "b" + } + ] + } + ] + } + ] + }, + { + "name": "breakLine", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a?" + } + ], + "method": "b" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/DoubleColonWhitespaces.kt b/test/datagen/kotlin/kotlin-compiler-tests/DoubleColonWhitespaces.kt new file mode 100644 index 000000000..9509d2969 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/DoubleColonWhitespaces.kt @@ -0,0 +1,17 @@ +fun tests() { + a:: b + a ::b + a :: b + + a?:: b + a ?::b + a ?:: b + a? ::b + a ? :: b + a ? ? :: b +} + +fun breakLine() { + a? + ::b +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/DynamicReceiver.json b/test/datagen/kotlin/kotlin-compiler-tests/DynamicReceiver.json new file mode 100644 index 000000000..991d312b5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/DynamicReceiver.json @@ -0,0 +1,65 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "receiver_type": { + "name": "dynamic", + "kind": "DYNAMIC" + } + }, + { + "name": "foo", + "receiver_type": { + "name": "dynamic?", + "kind": "OTHER" + } + }, + { + "name": "foo", + "receiver_type": { + "name": "dynamic", + "kind": "DYNAMIC" + } + }, + { + "name": "foo", + "receiver_type": { + "name": "dynamic", + "kind": "DYNAMIC" + } + }, + { + "name": "foo", + "receiver_type": { + "name": "dynamic", + "kind": "DYNAMIC" + } + }, + { + "name": "foo", + "receiver_type": { + "name": "dynamic", + "kind": "DYNAMIC" + } + } + ], + "variables": [ + { + "name": "foo", + "variable_type": { + "name": "dynamic.() -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/DynamicReceiver.kt b/test/datagen/kotlin/kotlin-compiler-tests/DynamicReceiver.kt new file mode 100644 index 000000000..946368769 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/DynamicReceiver.kt @@ -0,0 +1,16 @@ +fun dynamic.foo() +fun dynamic?.foo() +val dynamic.foo: Int +val dynamic?.foo: Int + +val foo: dynamic.() -> Unit + +// testing look-ahead with comments and whitespace + +fun dynamic . foo() +fun dynamic + .foo() +fun dynamic// line-comment + .foo() +fun dynamic/* +*/.foo() diff --git a/test/datagen/kotlin/kotlin-compiler-tests/DynamicTypes.json b/test/datagen/kotlin/kotlin-compiler-tests/DynamicTypes.json new file mode 100644 index 000000000..b302f6780 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/DynamicTypes.json @@ -0,0 +1,139 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "return_type": { + "name": "dynamic", + "kind": "DYNAMIC" + }, + "arguments": [ + { + "name": "p1", + "variable_type": { + "name": "dynamic", + "kind": "DYNAMIC" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "p2", + "variable_type": { + "name": "@a dynamic", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "p3", + "variable_type": { + "name": "foo.dynamic", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "p4", + "variable_type": { + "name": "dynamic.foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "p5", + "variable_type": { + "name": "dynamic", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "p6", + "variable_type": { + "name": "Foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "p7", + "variable_type": { + "name": "dynamic?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "p8", + "variable_type": { + "name": "(dynamic) -> dynamic", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/DynamicTypes.kt b/test/datagen/kotlin/kotlin-compiler-tests/DynamicTypes.kt new file mode 100644 index 000000000..0f8f033e5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/DynamicTypes.kt @@ -0,0 +1,10 @@ +fun foo( + p1: dynamic, + p2: @a dynamic, + p3: foo.dynamic, + p4: dynamic.foo, + p5: dynamic, + p6: Foo, + p7: dynamic?, + p8: (dynamic) -> dynamic +): dynamic \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EOLsOnRollback.json b/test/datagen/kotlin/kotlin-compiler-tests/EOLsOnRollback.json new file mode 100644 index 000000000..f4b4848fb --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EOLsOnRollback.json @@ -0,0 +1,111 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "r" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "4" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "f", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ] + } + ] + } + ] + } + ], + "methods": [ + { + "name": "foo" + } + ], + "type_declarations": [ + { + "name": "foo", + "kind": "CLASS" + }, + { + "name": "foo", + "kind": "CLASS" + }, + { + "name": "x", + "kind": "ALIAS", + "parents": [ + { + "name": "t", + "kind": "OTHER" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EOLsOnRollback.kt b/test/datagen/kotlin/kotlin-compiler-tests/EOLsOnRollback.kt new file mode 100644 index 000000000..d92e3e2f7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EOLsOnRollback.kt @@ -0,0 +1,13 @@ +fun foo() { + class foo + fun foo() + class foo + + typealias x = t + var r + + @a var foo = 4 + + 1 + @a val f +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EmptyFile.json b/test/datagen/kotlin/kotlin-compiler-tests/EmptyFile.json new file mode 100644 index 000000000..2deb301a3 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EmptyFile.json @@ -0,0 +1,7 @@ +{ + "namespaces": [ + { + "name": "" + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EmptyFile.kt b/test/datagen/kotlin/kotlin-compiler-tests/EmptyFile.kt new file mode 100644 index 000000000..e69de29bb diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumCommas.json b/test/datagen/kotlin/kotlin-compiler-tests/EnumCommas.json new file mode 100644 index 000000000..0c4075f07 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumCommas.json @@ -0,0 +1,69 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Color", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "fields": [ + { + "name": "NORTH", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + }, + { + "name": "SOUTH", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + }, + { + "name": "WEST", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + }, + { + "name": "EAST", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumCommas.kt b/test/datagen/kotlin/kotlin-compiler-tests/EnumCommas.kt new file mode 100644 index 000000000..8b4d8457e --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumCommas.kt @@ -0,0 +1,7 @@ +enum class Color { + NORTH, + SOUTH, + WEST, + EAST, + ; +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonInlineMember.json b/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonInlineMember.json new file mode 100644 index 000000000..71ff33329 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonInlineMember.json @@ -0,0 +1,49 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "My", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "methods": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "OTHER", + "other": "inline" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "fields": [ + { + "name": "FIRST", + "variable_type": { + "name": "My", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonInlineMember.kt b/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonInlineMember.kt new file mode 100644 index 000000000..0191ecece --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonInlineMember.kt @@ -0,0 +1,5 @@ +enum class My { + FIRST; + + inline fun foo() {} +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonMember.json b/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonMember.json new file mode 100644 index 000000000..f4bccc596 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonMember.json @@ -0,0 +1,43 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "My", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "fields": [ + { + "name": "FIRST", + "variable_type": { + "name": "My", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonMember.kt b/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonMember.kt new file mode 100644 index 000000000..0f5ac9561 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumEntrySemicolonMember.kt @@ -0,0 +1,5 @@ +enum class My { + FIRST; + + fun foo() {} +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumIn.json b/test/datagen/kotlin/kotlin-compiler-tests/EnumIn.json new file mode 100644 index 000000000..cb9a5c737 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumIn.json @@ -0,0 +1,33 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "fields": [ + { + "name": "in", + "variable_type": { + "name": "Foo", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumIn.kt b/test/datagen/kotlin/kotlin-compiler-tests/EnumIn.kt new file mode 100644 index 000000000..783e276b6 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumIn.kt @@ -0,0 +1,3 @@ +enum class Foo { + `in` +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumInline.json b/test/datagen/kotlin/kotlin-compiler-tests/EnumInline.json new file mode 100644 index 000000000..4c27d5e35 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumInline.json @@ -0,0 +1,33 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "My", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "fields": [ + { + "name": "inline", + "variable_type": { + "name": "My", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumInline.kt b/test/datagen/kotlin/kotlin-compiler-tests/EnumInline.kt new file mode 100644 index 000000000..29e488c67 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumInline.kt @@ -0,0 +1,3 @@ +enum class My { + inline +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumInlinePublic.json b/test/datagen/kotlin/kotlin-compiler-tests/EnumInlinePublic.json new file mode 100644 index 000000000..71d2393d2 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumInlinePublic.json @@ -0,0 +1,69 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "My", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "fields": [ + { + "name": "public", + "variable_type": { + "name": "My", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "OTHER", + "other": "inline" + } + ] + }, + { + "name": "private", + "variable_type": { + "name": "My", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "OTHER", + "other": "inner" + } + ] + } + ], + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumInlinePublic.kt b/test/datagen/kotlin/kotlin-compiler-tests/EnumInlinePublic.kt new file mode 100644 index 000000000..275bd8688 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumInlinePublic.kt @@ -0,0 +1,6 @@ +enum class My { + inline public, + inner private; + + companion object {} +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumShortCommas.json b/test/datagen/kotlin/kotlin-compiler-tests/EnumShortCommas.json new file mode 100644 index 000000000..1b72f493a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumShortCommas.json @@ -0,0 +1,157 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Color", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "rgb", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "rgb", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "RED", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0xFF000" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + }, + { + "name": "GREEN", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0x00FF00" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + }, + { + "name": "BLUE", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0x0000FF" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumShortCommas.kt b/test/datagen/kotlin/kotlin-compiler-tests/EnumShortCommas.kt new file mode 100644 index 000000000..75ca0105a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumShortCommas.kt @@ -0,0 +1,6 @@ +enum class Color(val rgb : Int) { + RED(0xFF000), + GREEN(0x00FF00), + BLUE(0x0000FF), + ; +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumShortWithOverload.json b/test/datagen/kotlin/kotlin-compiler-tests/EnumShortWithOverload.json new file mode 100644 index 000000000..d0b5441b7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumShortWithOverload.json @@ -0,0 +1,283 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Color", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "rgb", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "foo", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ], + "return_type": { + "name": "Int", + "kind": "OTHER" + } + } + ], + "fields": [ + { + "name": "rgb", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "RED", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "initializer": { + "kind": "NEW", + "anon_declaration": { + "name": "Color", + "kind": "ENUM", + "methods": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + }, + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0xFF000" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + }, + { + "name": "GREEN", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "initializer": { + "kind": "NEW", + "anon_declaration": { + "name": "Color", + "kind": "ENUM", + "methods": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + }, + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0x00FF00" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + }, + { + "name": "BLUE", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "initializer": { + "kind": "NEW", + "anon_declaration": { + "name": "Color", + "kind": "ENUM", + "methods": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + } + ] + } + }, + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0x0000FF" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/EnumShortWithOverload.kt b/test/datagen/kotlin/kotlin-compiler-tests/EnumShortWithOverload.kt new file mode 100644 index 000000000..b7957c762 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/EnumShortWithOverload.kt @@ -0,0 +1,13 @@ +enum class Color(val rgb : Int) { + RED(0xFF000) { + override fun foo(): Int { return 1 } + }, + GREEN(0x00FF00) { + override fun foo(): Int { return 2 } + }, + BLUE(0x0000FF) { + override fun foo(): Int { return 3 } + }; + + abstract fun foo(): Int +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Enums.json b/test/datagen/kotlin/kotlin-compiler-tests/Enums.json new file mode 100644 index 000000000..1b72f493a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Enums.json @@ -0,0 +1,157 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Color", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "rgb", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "rgb", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "RED", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0xFF000" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + }, + { + "name": "GREEN", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0x00FF00" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + }, + { + "name": "BLUE", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0x0000FF" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Enums.kt b/test/datagen/kotlin/kotlin-compiler-tests/Enums.kt new file mode 100644 index 000000000..dda485c81 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Enums.kt @@ -0,0 +1,7 @@ +enum class Color(val rgb : Int) { + RED(0xFF000), + GREEN(0x00FF00), + BLUE(0x0000FF) + + // the end +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ExtensionsWithQNReceiver.json b/test/datagen/kotlin/kotlin-compiler-tests/ExtensionsWithQNReceiver.json new file mode 100644 index 000000000..731dda7d2 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ExtensionsWithQNReceiver.json @@ -0,0 +1,24 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "size", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "LITERAL", + "literal": "1" + }, + "receiver_type": { + "name": "java.util.Map<*,*>", + "kind": "OTHER" + } + } + ] + } + ] +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ExtensionsWithQNReceiver.kt b/test/datagen/kotlin/kotlin-compiler-tests/ExtensionsWithQNReceiver.kt new file mode 100644 index 000000000..78ae76a6a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ExtensionsWithQNReceiver.kt @@ -0,0 +1,3 @@ +val java.util.Map<*,*>.size : Int + +fun java.util.Map<*,*>.size() : Int = 1 diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FloatingPointLiteral.json b/test/datagen/kotlin/kotlin-compiler-tests/FloatingPointLiteral.json new file mode 100644 index 000000000..73eeb671e --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FloatingPointLiteral.json @@ -0,0 +1,137 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "array", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "Any", + "kind": "GENERIC" + } + ], + "method": "array", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "1.0" + }, + { + "kind": "LITERAL", + "literal": "1e1" + }, + { + "kind": "LITERAL", + "literal": "1.0e1" + }, + { + "kind": "LITERAL", + "literal": "1e-1" + }, + { + "kind": "LITERAL", + "literal": "1.0e-1" + }, + { + "kind": "LITERAL", + "literal": "1F" + }, + { + "kind": "LITERAL", + "literal": "1.0F" + }, + { + "kind": "LITERAL", + "literal": "1e1F" + }, + { + "kind": "LITERAL", + "literal": "1.0e1F" + }, + { + "kind": "LITERAL", + "literal": "1e-1F" + }, + { + "kind": "LITERAL", + "literal": "1.0e-1F" + }, + { + "kind": "LITERAL", + "literal": "1f" + }, + { + "kind": "LITERAL", + "literal": "1.0f" + }, + { + "kind": "LITERAL", + "literal": "1e1f" + }, + { + "kind": "LITERAL", + "literal": "1.0e1f" + }, + { + "kind": "LITERAL", + "literal": "1e-1f" + }, + { + "kind": "LITERAL", + "literal": "1.0e-1f" + }, + { + "kind": "LITERAL", + "literal": ".1_1" + }, + { + "kind": "LITERAL", + "literal": "3.141_592" + }, + { + "kind": "LITERAL", + "literal": "1e1__3_7" + }, + { + "kind": "LITERAL", + "literal": "1_0f" + }, + { + "kind": "LITERAL", + "literal": "1e1_2f" + }, + { + "kind": "LITERAL", + "literal": "2_2.0f" + }, + { + "kind": "LITERAL", + "literal": ".3_3f" + }, + { + "kind": "LITERAL", + "literal": "3.14_16f" + }, + { + "kind": "LITERAL", + "literal": "6.022___137e+2_3f" + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FloatingPointLiteral.kt b/test/datagen/kotlin/kotlin-compiler-tests/FloatingPointLiteral.kt new file mode 100644 index 000000000..5e22205c6 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FloatingPointLiteral.kt @@ -0,0 +1,29 @@ +val array = array( + 1, + 1.0, + 1e1, + 1.0e1, + 1e-1, + 1.0e-1, + 1F, + 1.0F, + 1e1F, + 1.0e1F, + 1e-1F, + 1.0e-1F, + 1f, + 1.0f, + 1e1f, + 1.0e1f, + 1e-1f, + 1.0e-1f, + .1_1, + 3.141_592, + 1e1__3_7, + 1_0f, + 1e1_2f, + 2_2.0f, + .3_3f, + 3.14_16f, + 6.022___137e+2_3f +) \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FunctionCalls.json b/test/datagen/kotlin/kotlin-compiler-tests/FunctionCalls.json new file mode 100644 index 000000000..1766fc185 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FunctionCalls.json @@ -0,0 +1,778 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "f", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "bar", + "kind": "GENERIC" + } + ], + "method": "g", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "baz", + "kind": "GENERIC" + } + ], + "method": "h" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "i", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "s" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "j" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "s" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "k", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "s" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "l", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "s" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "m", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "s" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "a", + "kind": "GENERIC" + } + ], + "method": "n", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "s" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "a", + "kind": "GENERIC" + } + ], + "method": "o", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "s" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "p", + "method_args": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "a", + "kind": "GENERIC" + }, + { + "name": "b", + "kind": "GENERIC" + } + ], + "method": "qux" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "q", + "method_args": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "a", + "kind": "GENERIC" + }, + { + "name": "b", + "kind": "GENERIC" + } + ], + "method": "quux", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "r", + "method_args": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "corge" + }, + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + }, + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "s", + "method_args": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "grault" + }, + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "PAREN", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + }, + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + }, + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "t", + "method_args": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "garply" + }, + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + }, + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + }, + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "u", + "method_args": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "waldo" + }, + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "OP_MULT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + }, + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + }, + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "v", + "method_args": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "a", + "kind": "GENERIC" + }, + { + "name": "*", + "kind": "GENERIC" + }, + { + "name": "b", + "kind": "GENERIC" + } + ], + "method": "fred", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "w", + "method_args": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "plugh" + }, + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "LITERAL", + "literal": "\"\"" + }, + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + }, + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "*", + "kind": "GENERIC" + } + ], + "method": "xyzzy" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ], + "method": "_foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ], + "method": "__foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1_1" + } + ], + "method": "_foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ], + "method": "_1foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ], + "method": "_1_foo" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FunctionCalls.kt b/test/datagen/kotlin/kotlin-compiler-tests/FunctionCalls.kt new file mode 100644 index 000000000..aa224e5a2 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FunctionCalls.kt @@ -0,0 +1,40 @@ +fun foo() { + f(a) + g(a) + h + (a) + i {s} + j; + {s} + k { + s + } + l(a) { + s + } + m(a); + { + s + } + n(a) { + s + } + o(a); + { + s + } + p(qux) + q(quux(a)) + r(corge(a)) + s(grault(a)) + t(garply(a)) + u(waldo(a)) + v(fred(a)) + w(plugh(a)) + xyzzy<*>() + 1._foo() + 1.__foo() + 1_1._foo() + 1._1foo() + 1._1_foo() +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FunctionExpressions.json b/test/datagen/kotlin/kotlin-compiler-tests/FunctionExpressions.json new file mode 100644 index 000000000..3e29e9157 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FunctionExpressions.json @@ -0,0 +1,809 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "c", + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "" + } + ] + } + }, + { + "name": "c", + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "name" + } + ] + } + }, + { + "name": "c", + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "receiver_type": { + "name": "@[a] T", + "kind": "OTHER" + } + } + ] + } + }, + { + "name": "c", + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "receiver_type": { + "name": "@[a] T", + "kind": "OTHER" + } + } + ] + } + }, + { + "name": "c", + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T : (a) -> b", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "receiver_type": { + "name": "@[a()] T", + "kind": "OTHER" + } + } + ] + } + }, + { + "name": "outer", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "METHODDECL", + "methods": [ + { + "name": "name", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a] T", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "METHODDECL", + "methods": [ + { + "name": "name", + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a] T", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a] T", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T : (a) -> b", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a()] T", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "methods": [ + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T : @[a] (a) -> b", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a()] T", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "methods": [ + { + "name": "", + "return_type": { + "name": "bar?", + "kind": "OTHER" + }, + "receiver_type": { + "name": "A?", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "methods": [ + { + "name": "", + "return_type": { + "name": "bar?", + "kind": "OTHER" + }, + "receiver_type": { + "name": "A?", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "expression": { + "kind": "VARACCESS", + "variable": "a" + } + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "METHODDECL", + "methods": [ + { + "name": "name", + "expression": { + "kind": "VARACCESS", + "variable": "a" + } + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar", + "method_args": [ + { + "kind": "METHODDECL", + "methods": [ + { + "name": "name", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "a" + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "" + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "name" + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "name", + "receiver_type": { + "name": "T", + "kind": "OTHER" + } + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "receiver_type": { + "name": "@[a] T", + "kind": "OTHER" + } + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "name", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "receiver_type": { + "name": "@[a] T", + "kind": "OTHER" + } + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T : (a) -> b", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "receiver_type": { + "name": "@[a()] T", + "kind": "OTHER" + } + } + ] + } + }, + { + "name": "d", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "expression": { + "kind": "VARACCESS", + "variable": "a" + } + } + ] + } + }, + { + "name": "d", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "name", + "expression": { + "kind": "VARACCESS", + "variable": "a" + } + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ] + } + ] + } + }, + { + "name": "b", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "generic_parameters": [ + { + "name": "T : A", + "kind": "GENERIC" + } + ] + } + ] + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FunctionExpressions.kt b/test/datagen/kotlin/kotlin-compiler-tests/FunctionExpressions.kt new file mode 100644 index 000000000..1ae1ad4b7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FunctionExpressions.kt @@ -0,0 +1,37 @@ +val a = fun () +val a = fun name() +val a = fun T.name() +val a = fun @[a] T.(a : foo) : bar +val a = fun @[a] T.name(a : foo) : bar +val a = fun @[a()] T. b>(a : foo) : bar + +fun c() = fun (); +fun c() = fun name(); +fun c() = fun @[a] T.(); +fun c() = fun @[a] T.(a : foo) : bar; +fun c() = fun @[a()] T. b>(a : foo) : bar; + +val d = fun () = a +val d = fun name() = a +val a = @[a] fun () + +val b = fun () where T: A + +fun outer() { + bar(fun () {}) + bar(fun name() {}) + bar(fun @[a] T.() {}) + bar(fun @[a] T.name() {}) + + bar(fun @[a] T.(a : foo) : bar {}) + bar(fun @[a()] T. b>(a : foo) : bar {}) + + bar {fun @[a()] T. b>(a : foo) : bar {}} + + bar {fun A?.() : bar?} + bar {fun A? .() : bar?} + + bar(fun () = a) + bar(fun name() = a) + bar(@[a] fun name() = a) +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FunctionLiterals.json b/test/datagen/kotlin/kotlin-compiler-tests/FunctionLiterals.json new file mode 100644 index 000000000..ac850d7e5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FunctionLiterals.json @@ -0,0 +1,347 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "a", + "variable_type": { + "name": "b", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "a", + "variable_type": { + "name": "b", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "c", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "a", + "variable_type": { + "name": "b", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "c", + "variable_type": { + "name": "d", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "a", + "variable_type": { + "name": "(Int) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "c", + "variable_type": { + "name": "(Int) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "f" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FunctionLiterals.kt b/test/datagen/kotlin/kotlin-compiler-tests/FunctionLiterals.kt new file mode 100644 index 000000000..ba766a3bc --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FunctionLiterals.kt @@ -0,0 +1,17 @@ +fun foo() { + {} + + {foo} + + {a -> a} + + {x, y -> 1} + + {a: b -> f} + {a: b, c -> f} + {a: b, c: d -> f} + {a: (Int) -> Unit, c: (Int) -> Unit -> f} + + //{a: ((Int) -> Unit) ->} todo + //{[a] a: A -> } +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FunctionTypes.json b/test/datagen/kotlin/kotlin-compiler-tests/FunctionTypes.json new file mode 100644 index 000000000..1402e3d64 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FunctionTypes.json @@ -0,0 +1,199 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(@[a] a) -> b", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(a) -> b", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "() -> @[x] b", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "() -> Unit", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(a : @[a] a) -> b", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(a : a) -> b", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "() -> b", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "() -> Unit", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(a : @[a] a, foo, x : bar) -> b", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(foo, a : a) -> b", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(foo, a : (a) -> b) -> b", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(foo, a : (a) -> b) -> () -> Unit", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "T.() -> Unit", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "T.T.() -> Unit", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "T.T.() -> Unit", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "@[a] T.() -> Unit", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "@[a] T.T.() -> Unit", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "@[a] T.T.() -> Unit", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(a, ) -> b", + "kind": "OTHER" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FunctionTypes.kt b/test/datagen/kotlin/kotlin-compiler-tests/FunctionTypes.kt new file mode 100644 index 000000000..9ea1a0ae7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FunctionTypes.kt @@ -0,0 +1,24 @@ +typealias f = (@[a] a) -> b +typealias f = (a) -> b +typealias f = () -> @[x] b +typealias f = () -> Unit + +typealias f = (a : @[a] a) -> b +typealias f = (a : a) -> b +typealias f = () -> b +typealias f = () -> Unit + +typealias f = (a : @[a] a, foo, x : bar) -> b +typealias f = (foo, a : a) -> b +typealias f = (foo, a : (a) -> b) -> b +typealias f = (foo, a : (a) -> b) -> () -> Unit + +typealias f = T.() -> Unit +typealias f = T.T.() -> Unit +typealias f = T.T.() -> Unit + +typealias f = @[a] T.() -> Unit +typealias f = @[a] T.T.() -> Unit +typealias f = @[a] T.T.() -> Unit + +typealias f = (a, ) -> b diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FunctionsWithoutName.json b/test/datagen/kotlin/kotlin-compiler-tests/FunctionsWithoutName.json new file mode 100644 index 000000000..9cf9414b5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FunctionsWithoutName.json @@ -0,0 +1,307 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "" + }, + { + "name": "", + "receiver_type": { + "name": "T", + "kind": "OTHER" + } + }, + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "receiver_type": { + "name": "T", + "kind": "OTHER" + } + }, + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T : (a) -> b", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "receiver_type": { + "name": "T", + "kind": "OTHER" + } + }, + { + "name": "" + }, + { + "name": "", + "receiver_type": { + "name": "T", + "kind": "OTHER" + } + }, + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "receiver_type": { + "name": "T", + "kind": "OTHER" + } + }, + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T : (a) -> b", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "receiver_type": { + "name": "T", + "kind": "OTHER" + } + }, + { + "name": "", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "", + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a] T", + "kind": "OTHER" + } + }, + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a] T", + "kind": "OTHER" + } + }, + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T : (a) -> b", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a()] T", + "kind": "OTHER" + } + }, + { + "name": "", + "return_type": { + "name": "bar", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T : @[a] (a) -> b", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a()] T", + "kind": "OTHER" + } + }, + { + "name": "", + "return_type": { + "name": "bar?", + "kind": "OTHER" + }, + "receiver_type": { + "name": "A?", + "kind": "OTHER" + } + }, + { + "name": "", + "return_type": { + "name": "bar?", + "kind": "OTHER" + }, + "receiver_type": { + "name": "A?", + "kind": "OTHER" + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/FunctionsWithoutName.kt b/test/datagen/kotlin/kotlin-compiler-tests/FunctionsWithoutName.kt new file mode 100644 index 000000000..411a930cc --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/FunctionsWithoutName.kt @@ -0,0 +1,18 @@ +fun () +fun T.() +fun T.(a : foo) : bar +fun T. b>(a : foo) : bar + +fun (); +fun T.(); +fun T.(a : foo) : bar; +fun T. b>(a : foo) : bar; + +fun () {} +fun @[a] T.() {} +fun @[a] T.(a : foo) : bar {} +fun @[a()] T. b>(a : foo) : bar {} +fun @[a()] T. b>(a : foo) : bar {} + +fun A?.() : bar? +fun A? .() : bar? \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/IfWithPropery.json b/test/datagen/kotlin/kotlin-compiler-tests/IfWithPropery.json new file mode 100644 index 000000000..e6a718f9b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/IfWithPropery.json @@ -0,0 +1,147 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "f", + "initializer": { + "kind": "VARACCESS", + "variable": "a" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "f", + "initializer": { + "kind": "VARACCESS", + "variable": "a" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/IfWithPropery.kt b/test/datagen/kotlin/kotlin-compiler-tests/IfWithPropery.kt new file mode 100644 index 000000000..d28dec265 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/IfWithPropery.kt @@ -0,0 +1,5 @@ +val a = if(1) {var f = a;a} else {null} +val a = if(1) { + var f = a; + a +} else {null} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ImportSoftKW.json b/test/datagen/kotlin/kotlin-compiler-tests/ImportSoftKW.json new file mode 100644 index 000000000..fb8bc312f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ImportSoftKW.json @@ -0,0 +1,10 @@ +{ + "namespaces": [ + { + "name": "", + "imports": [ + "import.import.import.import as import" + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ImportSoftKW.kt b/test/datagen/kotlin/kotlin-compiler-tests/ImportSoftKW.kt new file mode 100644 index 000000000..610ff84e3 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ImportSoftKW.kt @@ -0,0 +1 @@ +import import.import.import.import as import \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Imports.json b/test/datagen/kotlin/kotlin-compiler-tests/Imports.json new file mode 100644 index 000000000..91b56ec96 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Imports.json @@ -0,0 +1,15 @@ +{ + "namespaces": [ + { + "name": "foo.bar.goo", + "imports": [ + "foo", + "foo.bar", + "foo as bar", + "foo.bar as bar", + "foo.*", + "foo.*" + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Imports.kt b/test/datagen/kotlin/kotlin-compiler-tests/Imports.kt new file mode 100644 index 000000000..625c277aa --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Imports.kt @@ -0,0 +1,8 @@ +package foo.bar.goo + +import foo +import foo.bar +import foo as bar +import foo.bar as bar +import foo.* +import foo. * \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Inner.json b/test/datagen/kotlin/kotlin-compiler-tests/Inner.json new file mode 100644 index 000000000..df1721347 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Inner.json @@ -0,0 +1,25 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Outer", + "kind": "CLASS", + "nested_declarations": [ + { + "name": "Inner", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "inner" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Inner.kt b/test/datagen/kotlin/kotlin-compiler-tests/Inner.kt new file mode 100644 index 000000000..361ea44f3 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Inner.kt @@ -0,0 +1,3 @@ +class Outer { + inner class Inner +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Interface.json b/test/datagen/kotlin/kotlin-compiler-tests/Interface.json new file mode 100644 index 000000000..7ac1c1477 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Interface.json @@ -0,0 +1,29 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "INTERFACE", + "methods": [ + { + "name": "f" + } + ], + "fields": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Interface.kt b/test/datagen/kotlin/kotlin-compiler-tests/Interface.kt new file mode 100644 index 000000000..06ba08dd1 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Interface.kt @@ -0,0 +1,4 @@ +interface Foo { + fun f() + val a +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/LocalDeclarations.json b/test/datagen/kotlin/kotlin-compiler-tests/LocalDeclarations.json new file mode 100644 index 000000000..72f2166b3 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/LocalDeclarations.json @@ -0,0 +1,124 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "out" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "out" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "5" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "4" + } + } + ] + } + ] + } + ], + "type_declarations": [ + { + "name": "foof", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "a" + }, + { + "kind": "ABSTRACT" + } + ] + }, + { + "name": "foof", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + }, + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "T.() -> Unit", + "kind": "OTHER" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/LocalDeclarations.kt b/test/datagen/kotlin/kotlin-compiler-tests/LocalDeclarations.kt new file mode 100644 index 000000000..105d91783 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/LocalDeclarations.kt @@ -0,0 +1,10 @@ +fun foo() { + out + 1 + @a abstract class foof {} + abstract @a class foof {} + + out val foo = 5 + @a var foo = 4 + typealias f = T.() -> Unit +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/LongPackageName.json b/test/datagen/kotlin/kotlin-compiler-tests/LongPackageName.json new file mode 100644 index 000000000..247a36f50 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/LongPackageName.json @@ -0,0 +1,7 @@ +{ + "namespaces": [ + { + "name": "foo.bar.baz.buzz" + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/LongPackageName.kt b/test/datagen/kotlin/kotlin-compiler-tests/LongPackageName.kt new file mode 100644 index 000000000..1df192287 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/LongPackageName.kt @@ -0,0 +1 @@ +package foo.bar.baz.buzz \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ModifierAsSelector.json b/test/datagen/kotlin/kotlin-compiler-tests/ModifierAsSelector.json new file mode 100644 index 000000000..56e4fed0b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ModifierAsSelector.json @@ -0,0 +1,49 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "Exception" + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "z", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "System" + } + ], + "variable": "out" + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ModifierAsSelector.kt b/test/datagen/kotlin/kotlin-compiler-tests/ModifierAsSelector.kt new file mode 100644 index 000000000..06688335b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ModifierAsSelector.kt @@ -0,0 +1,5 @@ +// JET-1 + +val z = System.out + +fun foo() { throw Exception(); } diff --git a/test/datagen/kotlin/kotlin-compiler-tests/NamedClassObject.json b/test/datagen/kotlin/kotlin-compiler-tests/NamedClassObject.json new file mode 100644 index 000000000..283edcd0b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/NamedClassObject.json @@ -0,0 +1,75 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + }, + { + "name": "B", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + }, + { + "name": "C", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + }, + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + }, + { + "name": "C", + "kind": "SINGLETON" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/NamedClassObject.kt b/test/datagen/kotlin/kotlin-compiler-tests/NamedClassObject.kt new file mode 100644 index 000000000..83232c7b3 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/NamedClassObject.kt @@ -0,0 +1,11 @@ +class A { + companion object Companion + + companion object B + + companion object C {} + + companion object + + object C +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/NewLinesValidOperations.json b/test/datagen/kotlin/kotlin-compiler-tests/NewLinesValidOperations.json new file mode 100644 index 000000000..a27b51340 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/NewLinesValidOperations.json @@ -0,0 +1,163 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "test", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "str", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"\"" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "str" + } + ], + "variable": "length" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "str" + } + ], + "variable": "length", + "safe": true + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "str" + } + ], + "new_type": { + "name": "String", + "kind": "OTHER" + } + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "str" + } + ], + "new_type": { + "name": "String", + "kind": "OTHER" + }, + "safe": true + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ELVIS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "str" + }, + { + "kind": "VARACCESS", + "variable": "foo" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LOGICAL_OR", + "expressions": [ + { + "kind": "LITERAL", + "literal": "true" + }, + { + "kind": "LITERAL", + "literal": "false" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LOGICAL_AND", + "expressions": [ + { + "kind": "LITERAL", + "literal": "false" + }, + { + "kind": "LITERAL", + "literal": "true" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/NewLinesValidOperations.kt b/test/datagen/kotlin/kotlin-compiler-tests/NewLinesValidOperations.kt new file mode 100644 index 000000000..61c0425d7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/NewLinesValidOperations.kt @@ -0,0 +1,32 @@ +fun test() { + val str = "" + + str + + .length + + str + + ?.length + + str + + as String + + str + + as? String + + str + + ?: foo + + true + + || false + + + false + + && true +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/NewlinesInParentheses.json b/test/datagen/kotlin/kotlin-compiler-tests/NewlinesInParentheses.json new file mode 100644 index 000000000..ad2a7869c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/NewlinesInParentheses.json @@ -0,0 +1,602 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "a" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "PAREN", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "PAREN", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + ] + } + ] + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "PAREN", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + }, + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "c" + }, + { + "kind": "VARACCESS", + "variable": "d" + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "c" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "d" + } + ] + } + ] + } + ] + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + }, + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "c" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "d" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "VARACCESS", + "variable": "d" + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "TYPECOMPARE", + "new_type": { + "name": "T\n ", + "kind": "OTHER" + } + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "IN", + "expressions": [ + { + "kind": "METHODCALL", + "method": "f" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "TYPECOMPARE", + "new_type": { + "name": "T\n ", + "kind": "OTHER" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "IN", + "expressions": [ + { + "kind": "METHODCALL", + "method": "f" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "METHODCALL", + "method": "f" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "e" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "f", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "new_type": { + "name": "T\n ", + "kind": "OTHER" + } + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/NewlinesInParentheses.kt b/test/datagen/kotlin/kotlin-compiler-tests/NewlinesInParentheses.kt new file mode 100644 index 000000000..d9a43bd55 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/NewlinesInParentheses.kt @@ -0,0 +1,38 @@ +fun foo() { + val a = a + b + val a = a + + b + val a = a + + b + val a = (a + + b) + val a = ({a + + b}) + val a = ({a + + b} + + b) + + val a = b[c + + d] + val a = b[{c + + d}] + val a = b[{c + + d} + + d] + + when (e) { + is T + + -> a + in f + () -> a + !is T + -> a + !in f + () -> a + f + () -> a + } + val f = a is T + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/NotIsAndNotIn.json b/test/datagen/kotlin/kotlin-compiler-tests/NotIsAndNotIn.json new file mode 100644 index 000000000..338c78d12 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/NotIsAndNotIn.json @@ -0,0 +1,100 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "test", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "new_type": { + "name": "B", + "kind": "OTHER" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "NOT_IN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "VARACCESS", + "variable": "B" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "METHODCALL", + "method": "isBoolean", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "METHODCALL", + "method": "inRange", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/NotIsAndNotIn.kt b/test/datagen/kotlin/kotlin-compiler-tests/NotIsAndNotIn.kt new file mode 100644 index 000000000..64e55c90b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/NotIsAndNotIn.kt @@ -0,0 +1,6 @@ +fun test() { + a !is B + a !in B + !isBoolean(a) + !inRange(a) +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ObjectLiteralAsStatement.json b/test/datagen/kotlin/kotlin-compiler-tests/ObjectLiteralAsStatement.json new file mode 100644 index 000000000..197283091 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ObjectLiteralAsStatement.json @@ -0,0 +1,77 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "main", + "arguments": [ + { + "name": "args", + "variable_type": { + "name": "Array", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "NEW", + "new_type": { + "name": "Thread", + "kind": "CLASS" + }, + "anon_declaration": { + "name": "", + "kind": "SINGLETON", + "parents": [ + { + "name": "Thread", + "kind": "CLASS" + } + ] + } + } + ], + "method": "run" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "NEW", + "anon_declaration": { + "name": "", + "kind": "SINGLETON" + } + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ObjectLiteralAsStatement.kt b/test/datagen/kotlin/kotlin-compiler-tests/ObjectLiteralAsStatement.kt new file mode 100644 index 000000000..436143a23 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ObjectLiteralAsStatement.kt @@ -0,0 +1,7 @@ +fun main(args : Array) { + object : Thread() { + }.run() + + object { + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ParameterType.json b/test/datagen/kotlin/kotlin-compiler-tests/ParameterType.json new file mode 100644 index 000000000..7904bde73 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ParameterType.json @@ -0,0 +1,345 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ], + "methods": [ + { + "name": "test1", + "arguments": [ + { + "name": "a", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "test2", + "arguments": [ + { + "name": "a", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "4" + } + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "test3", + "arguments": [ + { + "name": "c", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "test4", + "arguments": [ + { + "name": "a", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "ann", + "annotation_values": [ + { + "kind": "VARACCESS", + "variable": "parameter" + } + ] + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "test5", + "arguments": [ + { + "name": "a", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "test", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "TRY", + "statements": [ + { + "kind": "BLOCK" + }, + { + "kind": "CATCH", + "variable_declarations": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "arguments": [ + { + "name": "b", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "arguments": [ + { + "name": "b", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "4" + } + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "arguments": [ + { + "name": "b", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "(A) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "a", + "variable_type": { + "name": "(a: A) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/ParameterType.kt b/test/datagen/kotlin/kotlin-compiler-tests/ParameterType.kt new file mode 100644 index 000000000..d4eeb407d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/ParameterType.kt @@ -0,0 +1,24 @@ +fun test1(a) {} +fun test2(a = 4) {} +fun test3(c: Int) {} + +fun test4(@ann(parameter) a) {} +fun test5(@ann a) {} + +fun test() { + try { + + } + catch(a: Int) { + + } +} + +val a = fun (b) {} +val a = fun (b = 4) {} +val a = fun (b: Int) {} + +val a: (A) -> Unit +val a: (a: A) -> Unit + +class A(a: Int) \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Properties.json b/test/datagen/kotlin/kotlin-compiler-tests/Properties.json new file mode 100644 index 000000000..e69de29bb diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Properties.kt b/test/datagen/kotlin/kotlin-compiler-tests/Properties.kt new file mode 100644 index 000000000..3fcc59d4d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Properties.kt @@ -0,0 +1,45 @@ +val foo = bar.foo.bar + +val foo +@[a] val foo +val foo.bar + +val foo : T +@[a] val foo = bar +val foo.bar + get() {} + set(sad) = foo + + +val foo get +val foo set + +var foo + get + private set + +val foo.bar + get() {} + set + +val foo.bar + get + set(sad) = foo + +val foo = 5; get +val foo =1; get set + +var foo = 5 + get + private set + +fun foo() { + val foo = 5 + get() = 5 +} + +val IList.lastIndex : Int + get() = this.size - 1 + +val Int?.opt : Int +val Int? .opt : Int diff --git a/test/datagen/kotlin/kotlin-compiler-tests/PropertyInvokes.json b/test/datagen/kotlin/kotlin-compiler-tests/PropertyInvokes.json new file mode 100644 index 000000000..0e13b275d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/PropertyInvokes.json @@ -0,0 +1,95 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ], + "variable": "_some" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ], + "variable": "__some" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1_1" + } + ], + "variable": "_some" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ], + "variable": "_1some" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ], + "variable": "_1_some" + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/PropertyInvokes.kt b/test/datagen/kotlin/kotlin-compiler-tests/PropertyInvokes.kt new file mode 100644 index 000000000..dc8246344 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/PropertyInvokes.kt @@ -0,0 +1,7 @@ +fun foo() { + 1._some + 1.__some + 1_1._some + 1._1some + 1._1_some +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/QuotedIdentifiers.json b/test/datagen/kotlin/kotlin-compiler-tests/QuotedIdentifiers.json new file mode 100644 index 000000000..adaf1cf0b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/QuotedIdentifiers.json @@ -0,0 +1,52 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "$", + "kind": "CLASS" + }, + { + "name": "$$", + "kind": "CLASS" + }, + { + "name": " ", + "kind": "CLASS" + }, + { + "name": "1", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "package", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "`return`" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "`class`" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/QuotedIdentifiers.kt b/test/datagen/kotlin/kotlin-compiler-tests/QuotedIdentifiers.kt new file mode 100644 index 000000000..279c0a6b5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/QuotedIdentifiers.kt @@ -0,0 +1,8 @@ +@`return` fun `package`() { + `class`() +} + +class `$` +class `$$` +class ` ` +class `1` diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SemicolonAfterIf.json b/test/datagen/kotlin/kotlin-compiler-tests/SemicolonAfterIf.json new file mode 100644 index 000000000..190aca6ed --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SemicolonAfterIf.json @@ -0,0 +1,132 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "initializer": { + "kind": "VARACCESS", + "variable": "a" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "y", + "initializer": { + "kind": "OP_INC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "is_postfix": true + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "NEQ", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SemicolonAfterIf.kt b/test/datagen/kotlin/kotlin-compiler-tests/SemicolonAfterIf.kt new file mode 100644 index 000000000..b28a527b4 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SemicolonAfterIf.kt @@ -0,0 +1 @@ +fun foo(a: Int): Int { var x = a; var y = x++; if (y+1 != x) return -1; return x; } diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SimpleClassMembers.json b/test/datagen/kotlin/kotlin-compiler-tests/SimpleClassMembers.json new file mode 100644 index 000000000..1c7055c97 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SimpleClassMembers.json @@ -0,0 +1,378 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "foo", + "kind": "CLASS", + "methods": [ + { + "name": "foo" + } + ], + "fields": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "f" + } + ], + "nested_declarations": [ + { + "name": "foo", + "kind": "CLASS", + "methods": [ + { + "name": "foo" + } + ], + "fields": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "f" + } + ], + "nested_declarations": [ + { + "name": "foo", + "kind": "SINGLETON" + }, + { + "name": "Bar", + "kind": "CLASS" + }, + { + "name": "foo", + "kind": "ALIAS", + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + } + ] + }, + { + "name": "Bar", + "kind": "CLASS", + "methods": [ + { + "name": "foo" + } + ], + "fields": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "f" + } + ], + "nested_declarations": [ + { + "name": "foo", + "kind": "SINGLETON", + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + }, + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + }, + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "OTHER", + "other": "companion" + } + ], + "parents": [ + { + "name": "Fooo", + "kind": "CLASS" + } + ] + }, + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "OTHER", + "other": "companion" + } + ], + "parents": [ + { + "name": "Fooo", + "kind": "CLASS" + }, + { + "name": "Bar", + "kind": "DELEGATED", + "delegate": { + "kind": "VARACCESS", + "variable": "foo" + } + } + ] + }, + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "OTHER", + "other": "companion" + } + ], + "parents": [ + { + "name": "Fooo", + "kind": "CLASS" + }, + { + "name": "Bar", + "kind": "DELEGATED", + "delegate": { + "kind": "VARACCESS", + "variable": "foo" + } + }, + { + "name": "Goo", + "kind": "CLASS" + } + ] + } + ] + }, + { + "name": "Bar", + "kind": "CLASS" + }, + { + "name": "foo", + "kind": "ALIAS", + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + } + ] + }, + { + "name": "foo", + "kind": "ALIAS", + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + }, + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + }, + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "OTHER", + "other": "companion" + } + ] + }, + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "OTHER", + "other": "companion" + } + ], + "parents": [ + { + "name": "Fooo", + "kind": "CLASS" + } + ] + }, + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "OTHER", + "other": "companion" + } + ], + "parents": [ + { + "name": "Fooo", + "kind": "CLASS" + }, + { + "name": "Bar", + "kind": "DELEGATED", + "delegate": { + "kind": "VARACCESS", + "variable": "foo" + } + } + ] + }, + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "OTHER", + "other": "companion" + } + ], + "parents": [ + { + "name": "Fooo", + "kind": "CLASS" + }, + { + "name": "Bar", + "kind": "DELEGATED", + "delegate": { + "kind": "VARACCESS", + "variable": "foo" + } + }, + { + "name": "Goo", + "kind": "CLASS" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SimpleClassMembers.kt b/test/datagen/kotlin/kotlin-compiler-tests/SimpleClassMembers.kt new file mode 100644 index 000000000..9b84ce9e4 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SimpleClassMembers.kt @@ -0,0 +1,78 @@ +class foo { + + class foo { + object foo { + + } + + class Bar {} + + fun foo() + + val x + + var f + + typealias foo = bar + } + + class Bar { + object foo { + companion object { + + } + + private companion object { + + } + + private companion object : Fooo { + + } + + private companion object : Fooo, Bar by foo { + + } + + private companion object : Fooo, Bar by foo, Goo() + } + + class Bar {} + + fun foo() + + val x + + var f + + typealias foo = bar + } + + fun foo() + + val x + + var f + + typealias foo = bar + + companion object { + + } + + private companion object { + + } + + private companion object : Fooo { + + } + + private companion object : Fooo, Bar by foo { + + } + + private companion object : Fooo, Bar by foo, Goo() + + +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SimpleExpressions.json b/test/datagen/kotlin/kotlin-compiler-tests/SimpleExpressions.json new file mode 100644 index 000000000..f18063bff --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SimpleExpressions.json @@ -0,0 +1,874 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "a", + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "Unit" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "0x10" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "'1'" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"dsf\"" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"\"\"dsf\"\"\"" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "10.0" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "LITERAL", + "literal": "10" + } + ], + "variable": "dbl" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "LITERAL", + "literal": "10" + } + ], + "variable": "flt" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "LITERAL", + "literal": "10.0" + } + ], + "variable": "dbl" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "LITERAL", + "literal": "10" + } + ], + "variable": "lng" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "true" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "false" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "null" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "this" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "super" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "PAREN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "10" + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "Triple", + "method_args": [ + { + "kind": "LITERAL", + "literal": "10" + }, + { + "kind": "LITERAL", + "literal": "\"A\"" + }, + { + "kind": "LITERAL", + "literal": "0xf" + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "Foo", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "bar" + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "A", + "kind": "GENERIC" + } + ], + "method": "Foo", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "bar" + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "Foo" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "bar", + "kind": "GENERIC" + } + ], + "method": "Foo" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "NEW", + "new_type": { + "name": "Foo", + "kind": "CLASS" + }, + "anon_declaration": { + "name": "", + "kind": "SINGLETON", + "parents": [ + { + "name": "Foo", + "kind": "CLASS" + } + ] + } + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "Foo" + } + ] + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "10" + } + ] + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "BREAK" + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "BREAK", + "expressions": [ + { + "kind": "LABEL", + "literal": "la" + } + ] + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "CONTINUE" + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "CONTINUE", + "expressions": [ + { + "kind": "LABEL", + "literal": "la" + } + ] + } + ] + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "a", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "LITERAL", + "literal": "0xffffffff" + } + ], + "variable": "lng" + } + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "10" + } + ] + }, + { + "kind": "RETURN" + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "10" + } + ] + }, + { + "kind": "BREAK" + }, + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "la" + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "BREAK", + "expressions": [ + { + "kind": "LABEL", + "literal": "la" + } + ] + } + ] + } + ] + }, + { + "kind": "CONTINUE" + }, + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "la" + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "CONTINUE", + "expressions": [ + { + "kind": "LABEL", + "literal": "la" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SimpleExpressions.kt b/test/datagen/kotlin/kotlin-compiler-tests/SimpleExpressions.kt new file mode 100644 index 000000000..741edf5dc --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SimpleExpressions.kt @@ -0,0 +1,46 @@ +fun a( + a : foo = Unit, + a : foo = 10, + a : foo = 0x10, + a : foo = '1', + a : foo = "dsf", + a : foo = """dsf""", + a : foo = 10.0, + a : foo = 10.dbl, + a : foo = 10.flt, + a : foo = 10.0.dbl, + a : foo = 10.lng, + a : foo = true, + a : foo = false, + a : foo = null, + a : foo = this, + a : foo = super, + a : foo = (10), + a : foo = Triple(10, "A", 0xf), + a : foo = Foo(bar), + a : foo = Foo(bar), + a : foo = Foo(), + a : foo = Foo(), + a : foo = object : Foo{}, + a : foo = throw Foo(), + a : foo = return 10, + a : foo = break, + a : foo = break@la, + a : foo = continue, + a : foo = continue@la, + a : foo = 10, + a : foo = 10, + a : foo = 10, + a : foo = 10, + a : foo = 0xffffffff.lng +) { + return 10 + return + 10 + break + la@ + break@la + continue + la@ + continue@la +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SimpleModifiers.json b/test/datagen/kotlin/kotlin-compiler-tests/SimpleModifiers.json new file mode 100644 index 000000000..cebadb219 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SimpleModifiers.json @@ -0,0 +1,177 @@ +{ + "namespaces": [ + { + "name": "foo.bar.goo", + "declarations": [ + { + "name": "Bar", + "kind": "ANNOTATION", + "modifiers": [ + { + "kind": "ABSTRACT" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "OTHER", + "other": "annotation" + }, + { + "kind": "OTHER", + "other": "override" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "ABSTRACT" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + }, + { + "kind": "OTHER", + "other": "in" + }, + { + "kind": "OTHER", + "other": "out" + } + ], + "generic_parameters": [ + { + "name": "abstract open enum open annotation override open abstract private protected public internal in out T", + "kind": "GENERIC" + } + ], + "fields": [ + { + "name": "abstract", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "enum", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "annotation", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "override", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "abstract", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "private", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "protected", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "public", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "internal", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "lazy", + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SimpleModifiers.kt b/test/datagen/kotlin/kotlin-compiler-tests/SimpleModifiers.kt new file mode 100644 index 000000000..31ba846da --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SimpleModifiers.kt @@ -0,0 +1,44 @@ +package foo.bar.goo + +abstract +open +open +annotation +override +open +abstract +private +protected +public +internal +in +out + class Bar { + val abstract + val open + val enum + val open + val annotation + val override + val open + val abstract + val private + val protected + val public + val internal + val lazy +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywords.json b/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywords.json new file mode 100644 index 000000000..d3ac6a921 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywords.json @@ -0,0 +1,1784 @@ +{ + "namespaces": [ + { + "name": "foo.bar.goo", + "declarations": [ + { + "name": "Bar", + "kind": "ANNOTATION", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + }, + { + "kind": "ABSTRACT" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "OTHER", + "other": "annotation" + }, + { + "kind": "OTHER", + "other": "override" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "ABSTRACT" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + }, + { + "kind": "OTHER", + "other": "in" + }, + { + "kind": "OTHER", + "other": "out" + }, + { + "kind": "OTHER", + "other": "suspend" + } + ], + "generic_parameters": [ + { + "name": "abstract", + "kind": "GENERIC" + }, + { + "name": "abstract enum : T", + "kind": "GENERIC" + }, + { + "name": "out open", + "kind": "GENERIC" + }, + { + "name": "public protected private internal abstract open enum open annotation override open abstract private protected public internal open", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "A", + "kind": "DELEGATED", + "delegate": { + "kind": "VARACCESS", + "variable": "b" + } + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "B", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "coroutine.", + "expression": { + "kind": "VARACCESS", + "variable": "a" + } + }, + { + "name": "coroutine.", + "return_type": { + "name": "Unit", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "S", + "variable_type": { + "name": "s", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "abstract", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + } + ], + "return_type": { + "name": "abstract", + "kind": "OTHER" + } + }, + { + "name": "open", + "return_type": { + "name": "open", + "kind": "OTHER" + } + }, + { + "name": "enum", + "return_type": { + "name": "enum", + "kind": "OTHER" + } + }, + { + "name": "open", + "return_type": { + "name": "open", + "kind": "OTHER" + } + }, + { + "name": "annotation", + "return_type": { + "name": "annotation", + "kind": "OTHER" + } + }, + { + "name": "override", + "return_type": { + "name": "override", + "kind": "OTHER" + } + }, + { + "name": "open", + "return_type": { + "name": "open", + "kind": "OTHER" + } + }, + { + "name": "abstract", + "return_type": { + "name": "abstract", + "kind": "OTHER" + } + }, + { + "name": "private", + "return_type": { + "name": "private", + "kind": "OTHER" + } + }, + { + "name": "protected", + "return_type": { + "name": "protected", + "kind": "OTHER" + } + }, + { + "name": "public", + "return_type": { + "name": "public", + "kind": "OTHER" + } + }, + { + "name": "internal", + "return_type": { + "name": "internal", + "kind": "OTHER" + } + }, + { + "name": "lazy", + "return_type": { + "name": "lazy", + "kind": "OTHER" + } + }, + { + "name": "wraps", + "return_type": { + "name": "wraps", + "kind": "OTHER" + } + }, + { + "name": "import", + "return_type": { + "name": "import", + "kind": "OTHER" + } + }, + { + "name": "where", + "return_type": { + "name": "where", + "kind": "OTHER" + } + }, + { + "name": "by", + "return_type": { + "name": "by", + "kind": "OTHER" + } + }, + { + "name": "get", + "return_type": { + "name": "get", + "kind": "OTHER" + } + }, + { + "name": "set", + "return_type": { + "name": "set", + "kind": "OTHER" + } + }, + { + "name": "public", + "return_type": { + "name": "public", + "kind": "OTHER" + } + }, + { + "name": "private", + "return_type": { + "name": "private", + "kind": "OTHER" + } + }, + { + "name": "protected", + "return_type": { + "name": "protected", + "kind": "OTHER" + } + }, + { + "name": "internal", + "return_type": { + "name": "internal", + "kind": "OTHER" + } + }, + { + "name": "field", + "return_type": { + "name": "field", + "kind": "OTHER" + } + }, + { + "name": "property", + "return_type": { + "name": "property", + "kind": "OTHER" + } + }, + { + "name": "receiver", + "return_type": { + "name": "receiver", + "kind": "OTHER" + } + }, + { + "name": "param", + "return_type": { + "name": "param", + "kind": "OTHER" + } + }, + { + "name": "setparam", + "return_type": { + "name": "setparam", + "kind": "OTHER" + } + }, + { + "name": "lateinit", + "return_type": { + "name": "lateinit", + "kind": "OTHER" + } + }, + { + "name": "const", + "return_type": { + "name": "const", + "kind": "OTHER" + } + }, + { + "name": "test", + "arguments": [ + { + "name": "abstract", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "enum", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "annotation", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "override", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "abstract", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "private", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "protected", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "public", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "internal", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "lazy", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "wraps", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "import", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "where", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "by", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "get", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "set", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "public", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "private", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "protected", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "internal", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "field", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "property", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "receiver", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "param", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "setparam", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "lateinit", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "const", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + }, + { + "kind": "ABSTRACT" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "OTHER", + "other": "enum" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "OTHER", + "other": "annotation" + }, + { + "kind": "OTHER", + "other": "override" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "ABSTRACT" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "abstract", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + } + ] + }, + { + "name": "open", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "enum", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "annotation", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "override", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "abstract", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "private", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "protected", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "public", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "internal", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "lazy", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "wraps", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "import", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "where", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "by", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "get", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "set", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "public", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "private", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "protected", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "internal", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "field", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "property", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "receiver", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "param", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "setparam", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "lateinit", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "const", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "suspend", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "coroutine", + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "F", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "foo", + "variable_type": { + "name": "bar", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "abstract", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "enum", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "annotation", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "override", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "abstract", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "private", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "protected", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "public", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "internal", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "lazy", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "wraps", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "import", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "where", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "by", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "get", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "set", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "public", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "private", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "protected", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "internal", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "field", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "property", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "receiver", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "param", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "setparam", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "lateinit", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "const", + "variable_type": { + "name": "t", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "open", + "variable_type": { + "name": "b", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + }, + { + "kind": "ABSTRACT" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "OTHER", + "other": "enum" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "OTHER", + "other": "annotation" + }, + { + "kind": "OTHER", + "other": "override" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "ABSTRACT" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "foo", + "variable_type": { + "name": "bar", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "imports": [ + "foo" + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywords.kt b/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywords.kt new file mode 100644 index 000000000..06b4c3c48 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywords.kt @@ -0,0 +1,196 @@ +package foo.bar.goo + +import foo + +public protected private internal +abstract +open +open +annotation +override +open +abstract +private +protected +public +internal +in +out +suspend + class Bar (a : B) : A by b { + public protected private internal val abstract + val open + val enum + val open + val annotation + val override + val open + val abstract + val private + val protected + val public + val internal + val lazy + val wraps + val import + val where + val by + val get + val set + val public + val private + val protected + val internal + val field + val property + val receiver + val param + val setparam + val lateinit + val const + val suspend + val coroutine + get() = a + set(S : s) {} + + + public protected private internal + fun abstract () : abstract + fun open () : open + fun enum () : enum + fun open () : open + fun annotation () : annotation + fun override () : override + fun open () : open + fun abstract () : abstract + fun private () : private + fun protected () : protected + fun public () : public + fun internal () : internal + fun lazy () : lazy + fun wraps () : wraps + fun import () : import + fun where () : where + fun by () : by + fun get () : get + fun set () : set + fun public () : public + fun private () : private + fun protected () : protected + fun internal () : internal + fun field () : field + fun property () : property + fun receiver () : receiver + fun param () : param + fun setparam () : setparam + fun lateinit () : lateinit + fun const () : const + + fun test( + abstract : t, + open : t, + enum : t, + open : t, + annotation : t, + override : t, + open : t, + abstract : t, + private : t, + protected : t, + public : t, + internal : t, + lazy : t, + wraps : t, + import : t, + where : t, + by : t, + get : t, + set : t, + public : t, + private : t, + protected : t, + internal : t, + field : t, + property : t, + receiver : t, + param : t, + setparam : t, + lateinit : t, + const : t, + public protected private internal abstract + open + enum + open + annotation + override + open + abstract + private + protected + public + internal open : t + + ) + +} + + +class F(val foo : bar, + abstract : t, + open : t, + enum : t, + open : t, + annotation : t, + override : t, + open : t, + abstract : t, + private : t, + protected : t, + public : t, + internal : t, + lazy : t, + wraps : t, + import : t, + where : t, + by : t, + get : t, + set : t, + public : t, + private : t, + protected : t, + internal : t, + field : t, + property : t, + receiver : t, + param : t, + setparam : t, + lateinit : t, + const : t, + public protected private internal abstract + open + enum + open + annotation + override + open + abstract + private + protected + public + internal open : b +) { + +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywordsInTypeArguments.json b/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywordsInTypeArguments.json new file mode 100644 index 000000000..954e81db3 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywordsInTypeArguments.json @@ -0,0 +1,51 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "out abstract", + "kind": "GENERIC" + }, + { + "name": "out out", + "kind": "GENERIC" + } + ] + } + ], + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "Int", + "kind": "GENERIC" + } + ], + "method": "Foo" + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywordsInTypeArguments.kt b/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywordsInTypeArguments.kt new file mode 100644 index 000000000..63bdece71 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/SoftKeywordsInTypeArguments.kt @@ -0,0 +1,9 @@ +class Foo {} + +fun f() { + +// Foo + Foo + +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Super.json b/test/datagen/kotlin/kotlin-compiler-tests/Super.json new file mode 100644 index 000000000..f1ba0d9c7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Super.json @@ -0,0 +1,64 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "super" + } + ], + "method": "foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "super" + } + ], + "method": "foo" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "super@label" + } + ], + "method": "foo" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/Super.kt b/test/datagen/kotlin/kotlin-compiler-tests/Super.kt new file mode 100644 index 000000000..23333ad29 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/Super.kt @@ -0,0 +1,6 @@ +// KT-156 Fix the this syntax +fun foo() { + super.foo(); + super.foo(); + super@label.foo(); +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/TraitConstructor.json b/test/datagen/kotlin/kotlin-compiler-tests/TraitConstructor.json new file mode 100644 index 000000000..b237ecb38 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/TraitConstructor.json @@ -0,0 +1,96 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "TestTrait", + "kind": "INTERFACE", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "String", + "kind": "OTHER" + } + }, + { + "name": "c", + "variable_type": { + "name": "Double", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "String", + "kind": "OTHER" + } + } + ] + }, + { + "name": "TestTrait", + "kind": "INTERFACE", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/TraitConstructor.kt b/test/datagen/kotlin/kotlin-compiler-tests/TraitConstructor.kt new file mode 100644 index 000000000..f8f4d16f1 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/TraitConstructor.kt @@ -0,0 +1,2 @@ +interface TestTrait(val a: Int, var b: String, c: Double) +interface TestTrait() \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/TypeAlias.json b/test/datagen/kotlin/kotlin-compiler-tests/TypeAlias.json new file mode 100644 index 000000000..1f5e151e8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/TypeAlias.json @@ -0,0 +1,173 @@ +{ + "namespaces": [ + { + "name": "foo.bar.goo", + "declarations": [ + { + "name": "foo", + "kind": "ALIAS", + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + }, + { + "name": "foo", + "kind": "ALIAS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + }, + { + "name": "foo", + "kind": "ALIAS", + "generic_parameters": [ + { + "name": "T : foo", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + }, + { + "name": "foo", + "kind": "ALIAS", + "generic_parameters": [ + { + "name": "A", + "kind": "GENERIC" + }, + { + "name": "B", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + }, + { + "name": "foo", + "kind": "ALIAS", + "generic_parameters": [ + { + "name": "A", + "kind": "GENERIC" + }, + { + "name": "B : A", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + }, + { + "name": "foo", + "kind": "ALIAS", + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + }, + { + "name": "foo", + "kind": "ALIAS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + }, + { + "name": "foo", + "kind": "ALIAS", + "generic_parameters": [ + { + "name": "T : foo", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + }, + { + "name": "foo", + "kind": "ALIAS", + "generic_parameters": [ + { + "name": "A", + "kind": "GENERIC" + }, + { + "name": "B", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + }, + { + "name": "foo", + "kind": "ALIAS", + "generic_parameters": [ + { + "name": "A", + "kind": "GENERIC" + }, + { + "name": "B : A", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "bar", + "kind": "OTHER" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/TypeAlias.kt b/test/datagen/kotlin/kotlin-compiler-tests/TypeAlias.kt new file mode 100644 index 000000000..c622e0b0b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/TypeAlias.kt @@ -0,0 +1,14 @@ +package foo.bar.goo + +typealias foo = bar +typealias foo = bar +typealias foo = bar +typealias foo = bar +typealias foo = bar + +typealias foo = bar ; +typealias foo = bar ; + +typealias foo = bar ; +typealias foo = bar ; +typealias foo = bar ; diff --git a/test/datagen/kotlin/kotlin-compiler-tests/TypeConstraints.json b/test/datagen/kotlin/kotlin-compiler-tests/TypeConstraints.json new file mode 100644 index 000000000..e69de29bb diff --git a/test/datagen/kotlin/kotlin-compiler-tests/TypeConstraints.kt b/test/datagen/kotlin/kotlin-compiler-tests/TypeConstraints.kt new file mode 100644 index 000000000..03a8b3a12 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/TypeConstraints.kt @@ -0,0 +1,22 @@ +class foo + +class foo + where T : R { +} + +class foo { +} + +class foo + where T : R, + P : M, + T : Q { + val b = fun () + where T: B, + T : T, + T : D + val c + where T: B, + T : T, + T : D +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/TypeModifiers.json b/test/datagen/kotlin/kotlin-compiler-tests/TypeModifiers.json new file mode 100644 index 000000000..b1ef22d56 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/TypeModifiers.json @@ -0,0 +1,245 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f1", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@a a", + "kind": "OTHER" + } + }, + { + "name": "f2", + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "(@a a.(a) -> a)", + "kind": "OTHER" + } + } + ], + "variables": [ + { + "name": "p1", + "variable_type": { + "name": "suspend a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p2", + "variable_type": { + "name": "suspend (a) -> a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p3", + "variable_type": { + "name": "suspend (a) -> suspend a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p4", + "variable_type": { + "name": "suspend a.() -> a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p4a", + "variable_type": { + "name": "@a a.() -> a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p5", + "variable_type": { + "name": "(suspend a).() -> a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p5a", + "variable_type": { + "name": "(@a a).() -> a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p6", + "variable_type": { + "name": "a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p7", + "variable_type": { + "name": "a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p8", + "variable_type": { + "name": "a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p9", + "variable_type": { + "name": "a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p10", + "variable_type": { + "name": "suspend a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p11", + "variable_type": { + "name": "suspend @a a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p12", + "variable_type": { + "name": "@a suspend a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p13", + "variable_type": { + "name": "@a suspend @a a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p14", + "variable_type": { + "name": "@[a] suspend @[a] a", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "p15", + "variable_type": { + "name": "suspend (suspend (() -> Unit)) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/TypeModifiers.kt b/test/datagen/kotlin/kotlin-compiler-tests/TypeModifiers.kt new file mode 100644 index 000000000..e86c2096c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/TypeModifiers.kt @@ -0,0 +1,20 @@ +val p1: suspend a +val p2: suspend (a) -> a +val p3: suspend (a) -> suspend a +val p4: suspend a.() -> a +val p4a: @a a.() -> a +val p5: (suspend a).() -> a +val p5a: (@a a).() -> a +val p6: a +val p7: a +val p8: a +val p9: a +val p10: suspend a +val p11: suspend @a a +val p12: @a suspend a +val p13: @a suspend @a a +val p14: @[a] suspend @[a] a +val p15: suspend (suspend (() -> Unit)) -> Unit + +@a fun @a a.f1() {} +fun (@a a.(a) -> a).f2() {} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable.json b/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable.json new file mode 100644 index 000000000..9c54c9efb --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable.json @@ -0,0 +1,314 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "test", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x1", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "foo" + } + } + ] + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x2t", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "y2t", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "foo" + } + } + ] + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARDECL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo" + } + ], + "variable_decls": [ + { + "name": "x3", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x4", + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARDECL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo" + } + ], + "variable_decls": [ + { + "name": "y3t", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "y4", + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARDECL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo" + } + ], + "variable_decls": [ + { + "name": "z3", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "z4t", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARDECL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo" + } + ], + "variable_decls": [ + { + "name": "w3t", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "w4t", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x6a", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "foo" + } + } + ] + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x7a", + "variable_type": { + "name": "@Ann T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "foo" + } + } + ] + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x8a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + } + ] + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable.kt b/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable.kt new file mode 100644 index 000000000..7bac1fed5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable.kt @@ -0,0 +1,12 @@ +fun test() { + when (val x1 = foo) {} + when (val x2t: T) {} + when (val y2t: T = foo) {} + when (val (x3, x4) = foo) {} + when (val (y3t: T, y4) = foo) {} + when (val (z3, z4t: T) = foo) {} + when (val (w3t: T, w4t: T) = foo) {} + when (@Ann val x6a = foo) {} + when (val x7a: @Ann T = foo) {} + when (val x8a = @Ann foo) {} +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable_SoftModifierName.json b/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable_SoftModifierName.json new file mode 100644 index 000000000..27d054e0f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable_SoftModifierName.json @@ -0,0 +1,263 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "test", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "abstract" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "enum" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "open" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "inner" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "override" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "private" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "public" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "internal" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "protected" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "out" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "final" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "vararg" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "reified" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "companion" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "sealed" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "lateinit" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "inline" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "noinline" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "tailrec" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "external" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "annotation" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "crossinline" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "const" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "operator" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "infix" + } + ] + }, + { + "kind": "SWITCH", + "conditions": [ + { + "kind": "VARACCESS", + "variable": "suspend" + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable_SoftModifierName.kt b/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable_SoftModifierName.kt new file mode 100644 index 000000000..65319db9f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/WhenWithSubjectVariable_SoftModifierName.kt @@ -0,0 +1,29 @@ +fun test() { + when (abstract) {} + when (enum) {} + when (open) {} + when (inner) {} + when (override) {} + when (private) {} + when (public) {} + when (internal) {} + when (protected) {} + when (out) {} // NB 'in' is a hard keyword + when (final) {} + when (vararg) {} + when (reified) {} + when (companion) {} + when (sealed) {} + when (lateinit) {} + when (data) {} + when (inline) {} + when (noinline) {} + when (tailrec) {} + when (external) {} + when (annotation) {} + when (crossinline) {} + when (const) {} + when (operator) {} + when (infix) {} + when (suspend) {} +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotatedExpressions.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotatedExpressions.json new file mode 100644 index 000000000..83dec4ce6 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotatedExpressions.json @@ -0,0 +1,59 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotatedExpressions.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotatedExpressions.kt new file mode 100644 index 000000000..713352d28 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotatedExpressions.kt @@ -0,0 +1,5 @@ +fun foo() { + @[a] foo + 1 + @[a] this +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/Annotations.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/Annotations.json new file mode 100644 index 000000000..5fb87ee38 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/Annotations.json @@ -0,0 +1,105 @@ +{ + "namespaces": [ + { + "name": "foo.bar.goo", + "declarations": [ + { + "name": "Bar", + "kind": "ENUM", + "modifiers": [ + { + "kind": "ABSTRACT" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "OTHER", + "other": "enum" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "OTHER", + "other": "annotation" + }, + { + "kind": "OTHER", + "other": "override" + }, + { + "kind": "OTHER", + "other": "open" + }, + { + "kind": "ABSTRACT" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "foo", + "annotation_values": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + }, + { + "kind": "ANNOTATION", + "annotation_name": "ina" + }, + { + "kind": "ANNOTATION", + "annotation_name": "foo.bar.goo.doo.foo.foo" + }, + { + "kind": "ANNOTATION", + "annotation_name": "df" + }, + { + "kind": "OTHER", + "other": "in" + }, + { + "kind": "ANNOTATION", + "annotation_name": "sdfsdf" + }, + { + "kind": "OTHER", + "other": "out" + } + ], + "generic_parameters": [ + { + "name": "abstract open @[sdfsdf(1+1) a] @[sdfsdf(1+1)] @[a() sdfsdf(1+1)] enum open annotation override open abstract @[sdfsd sdfsd a.b.f.c] private protected public internal in out T", + "kind": "GENERIC" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/Annotations.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/Annotations.kt new file mode 100644 index 000000000..e7866b0bd --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/Annotations.kt @@ -0,0 +1,39 @@ +package foo.bar.goo + +abstract +open +enum +open +annotation +override +open +abstract +private +protected +public +internal +@[foo(a, b) ina foo.bar.goo.doo.foo.foo] +@[df] +in +@[sdfsdf] +out + class Bar { +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotationsOnPatterns.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotationsOnPatterns.json new file mode 100644 index 000000000..108571880 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotationsOnPatterns.json @@ -0,0 +1,51 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "TYPECOMPARE", + "new_type": { + "name": "@[a] T", + "kind": "OTHER" + } + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "d" + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "e" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotationsOnPatterns.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotationsOnPatterns.kt new file mode 100644 index 000000000..99ff93738 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/AnnotationsOnPatterns.kt @@ -0,0 +1,6 @@ +fun foo() { + + when (e) { + is @[a] T -> d + } +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnNullableTypes.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnNullableTypes.json new file mode 100644 index 000000000..16cc35e51 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnNullableTypes.json @@ -0,0 +1,234 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "arguments": [ + { + "name": "i", + "variable_type": { + "name": "@a Int?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "l", + "variable_type": { + "name": "List<@a Int?>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "bar", + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@a Int?", + "kind": "OTHER" + } + }, + { + "name": "foo1", + "arguments": [ + { + "name": "i", + "variable_type": { + "name": "@b(1) Int?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo1", + "arguments": [ + { + "name": "l", + "variable_type": { + "name": "List<@b(1) Int?>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "bar1", + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@b(1) Int?", + "kind": "OTHER" + } + }, + { + "name": "foo2", + "arguments": [ + { + "name": "i", + "variable_type": { + "name": "@[a b(1)] Int?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo2", + "arguments": [ + { + "name": "l", + "variable_type": { + "name": "List<@[a b(1)] Int?>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "bar2", + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a b(1)] Int?", + "kind": "OTHER" + } + } + ], + "variables": [ + { + "name": "baz", + "variable_type": { + "name": "@a Int?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "baz1", + "variable_type": { + "name": "@b(1) Int?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "baz2", + "variable_type": { + "name": "@[a b(1)] Int?", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnNullableTypes.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnNullableTypes.kt new file mode 100644 index 000000000..36cc248de --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnNullableTypes.kt @@ -0,0 +1,25 @@ +fun foo(i: @a Int?) {} + +fun foo(l: List<@a Int?>) {} + +fun @a Int?.bar() {} + +val baz: @a Int? + + +fun foo1(i: @b(1) Int?) {} + +fun foo1(l: List<@b(1) Int?>) {} + +fun @b(1) Int?.bar1() {} + +val baz1: @b(1) Int? + + +fun foo2(i: @[a b(1)] Int?) {} + +fun foo2(l: List<@[a b(1)] Int?>) {} + +fun @[a b(1)] Int?.bar2() {} + +val baz2: @[a b(1)] Int? \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnParenthesizedTypes.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnParenthesizedTypes.json new file mode 100644 index 000000000..1a222bb7d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnParenthesizedTypes.json @@ -0,0 +1,173 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "receiverArgument", + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "B<(@A C)>", + "kind": "OTHER" + } + }, + { + "name": "parameter", + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "(@A C)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "parameterArgument", + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "B<(@A C)>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "returnValue", + "return_type": { + "name": "(@A C)", + "kind": "OTHER" + } + }, + { + "name": "returnTypeParameterValue", + "return_type": { + "name": "(@A T)", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ] + }, + { + "name": "returnArgument", + "return_type": { + "name": "B<(@A C)>", + "kind": "OTHER" + } + } + ], + "variables": [ + { + "name": "lambdaType", + "variable_type": { + "name": "(@A() (() -> C))", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "lambdaParameter", + "variable_type": { + "name": "((@A C)) -> C", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "lambdaParameterNP", + "variable_type": { + "name": "(@A C) -> C", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "lambdaReturnValue", + "variable_type": { + "name": "() -> (@A C)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "lambdaReceiver", + "variable_type": { + "name": "(@A C).() -> C", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "lambdaParameterNP", + "variable_type": { + "name": "(@A C) -> C", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnParenthesizedTypes.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnParenthesizedTypes.kt new file mode 100644 index 000000000..7cd3eab0c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/annotationsOnParenthesizedTypes.kt @@ -0,0 +1,22 @@ +fun B<(@A C)>.receiverArgument() {} + +fun parameter(a: (@A C)) {} + +fun parameterArgument(a: B<(@A C)>) {} + +fun returnValue(): (@A C) + +fun returnTypeParameterValue(): (@A T) + +fun returnArgument(): B<(@A C)> + +val lambdaType: (@A() (() -> C)) + +val lambdaParameter: ((@A C)) -> C +val lambdaParameterNP: (@A C) -> C + +val lambdaReturnValue: () -> (@A C) + +val lambdaReceiver: (@A C).() -> C + +val lambdaParameterNP: (@A C) -> C \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationAtFileStart.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationAtFileStart.json new file mode 100644 index 000000000..6cd8871e6 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationAtFileStart.json @@ -0,0 +1,19 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationAtFileStart.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationAtFileStart.kt new file mode 100644 index 000000000..9ed8ea8b8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationAtFileStart.kt @@ -0,0 +1 @@ +@ann class A diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationValueArgumentsAmbiguity.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationValueArgumentsAmbiguity.json new file mode 100644 index 000000000..4e656be93 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationValueArgumentsAmbiguity.json @@ -0,0 +1,156 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann", + "annotation_values": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "it", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "it" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "it", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "it" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationValueArgumentsAmbiguity.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationValueArgumentsAmbiguity.kt new file mode 100644 index 000000000..458538599 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/annotationValueArgumentsAmbiguity.kt @@ -0,0 +1,7 @@ +fun foo() { + @ann ({ it -> it + 1}) // lambda parsed as argument of annotation, and annotated expression is "print(1)" + print(1) + + @ann() ({ it -> it + 1}) // lambda in parenthesises annotated, "print(1)" is separated expression + print(1) +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressions.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressions.json new file mode 100644 index 000000000..c35491a67 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressions.json @@ -0,0 +1,611 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x0", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann0" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "foo0" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x1" + }, + { + "kind": "METHODCALL", + "method": "foo1" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann1" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x2" + }, + { + "kind": "METHODCALL", + "method": "foo2" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann2" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x22" + }, + { + "kind": "METHODCALL", + "method": "foo22" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann21" + }, + { + "kind": "ANNOTATION", + "annotation_name": "ann22" + }, + { + "kind": "ANNOTATION", + "annotation_name": "ann23" + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x3" + }, + { + "kind": "METHODCALL", + "method": "foo3" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann3" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "100" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x4" + }, + { + "kind": "METHODCALL", + "method": "foo4" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann4" + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "100" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x41" + }, + { + "kind": "METHODCALL", + "method": "foo41" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann41" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "GT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x42" + }, + { + "kind": "METHODCALL", + "method": "foo42" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann42" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x43" + }, + { + "kind": "METHODCALL", + "method": "foo43" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann43" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "GT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + }, + { + "kind": "LITERAL", + "literal": "4" + } + ] + } + ] + }, + { + "kind": "WHILE", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x44" + }, + { + "kind": "METHODCALL", + "method": "foo44" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann44" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LITERAL", + "literal": "true" + } + ] + }, + { + "kind": "DO", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x45" + }, + { + "kind": "METHODCALL", + "method": "foo45" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LITERAL", + "literal": "true" + } + ] + }, + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x46" + }, + { + "kind": "METHODCALL", + "method": "foo46" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann46" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x5" + }, + { + "kind": "METHODCALL", + "method": "foo5" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann5" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ELVIS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x6" + }, + { + "kind": "OTHER", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x7" + }, + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x9" + }, + { + "kind": "LITERAL", + "literal": "10" + } + ] + } + ], + "literal": "infix" + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann6" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "STATEMENT", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann7" + } + ], + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "Type", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann8" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressions.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressions.kt new file mode 100644 index 000000000..0bcd8040c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressions.kt @@ -0,0 +1,69 @@ +fun foo() { + @ann0 + var x0 = foo0() + + @ann1 + // comment + /* comment */ + x1 = foo1() + + // many empty new lines + @ann2 + + + x2 += foo2() + + @ann21 @ann22 + + @ann23 + x22 += foo22() + + for (i in 1..100) { + @ann3 + x3 += foo3() + } + + for (i in 1..100) + @ann4 + x4 += foo4() + + if (1 > 2) + @ann41 + x41 += foo41() + + if (3 > 4) + @ann42 + x42 += foo42() + else + @ann43 + x43 += foo43() + + while (true) + @ann44 + x44 += foo44() + + do + @ann + x45 += foo45() + while (true) + + when (1) { + 1 -> + @ann46 + x46 += foo46() + } + + a.filter { + @ann5 + x5 += foo5() + } + + @ann6 + x6 ?: x7 infix x9 + 10 + + @ann7 + return 1 + + @ann8 + x as Type +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressionsNoNewLine.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressionsNoNewLine.json new file mode 100644 index 000000000..362ff9c2a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressionsNoNewLine.json @@ -0,0 +1,583 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x0", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann0" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "foo0" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x1", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann1" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo1" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x2", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann2" + }, + { + "kind": "ANNOTATION", + "annotation_name": "ann22" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo2" + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x3", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann3" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo3" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "100" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x4", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann4" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo4" + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "100" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x41", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann41" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo41" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "GT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x42", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann42" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo42" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x43", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann43" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo43" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "GT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + }, + { + "kind": "LITERAL", + "literal": "4" + } + ] + } + ] + }, + { + "kind": "WHILE", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x44", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann44" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo44" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LITERAL", + "literal": "true" + } + ] + }, + { + "kind": "DO", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x45", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo45" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LITERAL", + "literal": "true" + } + ] + }, + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x46", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann46" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo46" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x5", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann5" + } + ] + }, + { + "kind": "METHODCALL", + "method": "foo5" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ELVIS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x6", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann6" + } + ] + }, + { + "kind": "OTHER", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x7" + }, + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x9" + }, + { + "kind": "LITERAL", + "literal": "10" + } + ] + } + ], + "literal": "infix" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "STATEMENT", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann7" + } + ], + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann8" + } + ] + } + ], + "new_type": { + "name": "Type", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressionsNoNewLine.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressionsNoNewLine.kt new file mode 100644 index 000000000..34a15fd5d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/blockLevelExpressionsNoNewLine.kt @@ -0,0 +1,44 @@ +fun foo() { + @ann0 var x0 = foo0() + + @ann1 x1 = foo1() + + @ann2 @ann22 x2 += foo2() + + for (i in 1..100) { + @ann3 x3 += foo3() + } + + for (i in 1..100) + @ann4 x4 += foo4() + + if (1 > 2) + @ann41 x41 += foo41() + + if (3 > 4) + @ann42 x42 += foo42() + else + @ann43 x43 += foo43() + + while (true) + @ann44 x44 += foo44() + + do + @ann x45 += foo45() + while (true) + + when (1) { + 1 -> + @ann46 x46 += foo46() + } + + a.filter { + @ann5 x5 += foo5() + } + + @ann6 x6 ?: x7 infix x9 + 10 + + @ann7 return 1 + + @ann8 x as Type +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/enumEntries.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/enumEntries.json new file mode 100644 index 000000000..310e69781 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/enumEntries.json @@ -0,0 +1,187 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "methods": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "fields": [ + { + "name": "X", + "variable_type": { + "name": "A", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "" + } + ], + "new_type": { + "name": "A", + "kind": "ENUM" + } + } + ] + }, + { + "name": "Y", + "variable_type": { + "name": "A", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + } + ], + "initializer": { + "kind": "NEW", + "anon_declaration": { + "name": "A", + "kind": "ENUM" + } + }, + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "" + } + ], + "new_type": { + "name": "A", + "kind": "ENUM" + } + } + ] + }, + { + "name": "Z", + "variable_type": { + "name": "A", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "" + } + ], + "new_type": { + "name": "A", + "kind": "ENUM" + } + } + ] + }, + { + "name": "Q", + "variable_type": { + "name": "A", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + }, + { + "kind": "ANNOTATION", + "annotation_name": "private" + } + ] + }, + { + "name": "W", + "variable_type": { + "name": "A", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/enumEntries.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/enumEntries.kt new file mode 100644 index 000000000..942933b9a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/enumEntries.kt @@ -0,0 +1,14 @@ +enum class A { + @[Ann] @Ann(1) X(), + + @Ann Y() {}, + + private @Ann() Z(), + + @Ann @private Q, + + // TODO: try to make Ann() working here (?) + @Ann() W; + + @Ann fun foo() {} +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/modifierAtFileStart.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/modifierAtFileStart.json new file mode 100644 index 000000000..b732c1183 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/modifierAtFileStart.json @@ -0,0 +1,19 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "public" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/modifierAtFileStart.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/modifierAtFileStart.kt new file mode 100644 index 000000000..a08a642dd --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/at/modifierAtFileStart.kt @@ -0,0 +1 @@ +@public class A diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withParameter.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withParameter.json new file mode 100644 index 000000000..a992dabc1 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withParameter.json @@ -0,0 +1,604 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "@Foo(10 as @Foo suspend (Int) -> ((Int) -> Unit)) suspend (suspend (Int) -> ((Int) -> Unit)) -> Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "ABSTRACT" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "x.", + "return_type": { + "name": "(@Foo(10) suspend (Int) -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@Foo({}) ((x: @Foo(10) (@Foo(11) () -> Int) -> Int) -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "suspend @Foo(10) (x: @Foo(10) (@Foo(\"\") (x: kotlin.Any) -> Int) -> Int) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Comparable<@Foo(10) @Bar(10) @Foo(listOf(10)) (x: kotlin.Any) -> Unit>", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo(10) (@Foo({ x: Int -> 10}) kotlin.Any)->()->Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "x" + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "suspend @Foo(10) @Bar(10 + @Foo 3) (kotlin.Any) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "@Foo(10) suspend @Bar(throw Exception()) (Coomparable) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "suspend @Foo(null) (Coomparable<@Foo(10) @Bar(10) @Foo(10) () -> Unit>) -> () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "@Foo(10) @Bar(10) @Foo(Any) (Any) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "vararg" + } + ] + } + ], + "expression": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "foo", + "return_type": { + "name": "@Foo.Bar(@Foo x) suspend (Nothing) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "return_type": { + "name": "() -> @Foo.Bar('1') suspend (Bar) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Any", + "kind": "OTHER" + }, + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "@Foo(\"\") (Coomparable) -> Unit", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo(object {}) (()->Unit)-> ()->Unit) -> Unit", + "kind": "OTHER" + }, + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK" + } + ], + "conditions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "@Foo({}) @Bar(10) @Foo(10) (()->Unit) -> Unit", + "kind": "OTHER" + } + } + ], + "new_type": { + "name": "suspend @Foo(10) @Bar(10) @Foo(10) (()->Unit) -> Unit", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "(@Foo({}) suspend (()->Unit) -> (()->Unit) -> Unit) -> Unit", + "kind": "OTHER" + } + } + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo(10) suspend (Int) -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@Foo({}) ((x: @Foo(10) (@Foo(11) () -> Int) -> Int) -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "suspend @Foo(10) (x: @Foo(10) (@Foo(\"\") (x: kotlin.Any) -> Int) -> Int) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Comparable<@Foo(10) @Bar(10) @Foo(listOf(10)) (x: kotlin.Any) -> Unit>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "new_type": { + "name": "@Foo({ x: Int -> 10}) suspend (x: @Foo(10) Foo) -> (y: @Foo(10) Bar) -> Unit", + "kind": "OTHER" + } + } + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withParameter.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withParameter.kt new file mode 100644 index 000000000..ff04d4ef8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withParameter.kt @@ -0,0 +1,47 @@ +// Issue: KT-31734 + +val x: (@Foo(10) suspend (Int) -> Unit) get() = {} + +val x: @Foo({}) ((x: @Foo(10) (@Foo(11) () -> Int) -> Int) -> Unit) get() = {} + +val x: suspend @Foo(10) (x: @Foo(10) (@Foo("") (x: kotlin.Any) -> Int) -> Int) -> Unit get() = {} + +val x: Comparable<@Foo(10) @Bar(10) @Foo(listOf(10)) (x: kotlin.Any) -> Unit> get() = {} + +val x: Any = {} as @Foo({ x: Int -> 10}) suspend (x: @Foo(10) Foo) -> (y: @Foo(10) Bar) -> Unit + +fun foo(x: (@Foo(10) (@Foo({ x: Int -> 10}) kotlin.Any)->()->Unit)) = x + +fun foo(x: suspend @Foo(10) @Bar(10 + @Foo 3) (kotlin.Any) -> Unit = { x: Int -> x }) {} + +fun foo() { + val x: @Foo(10) suspend @Bar(throw Exception()) (Coomparable) -> Unit = {} +} + +fun foo() { + val x = { x: suspend @Foo(null) (Coomparable<@Foo(10) @Bar(10) @Foo(10) () -> Unit>) -> () -> Unit -> x } +} + +abstract class A { + abstract var x: @Foo(10 as @Foo suspend (Int) -> ((Int) -> Unit)) suspend (suspend (Int) -> ((Int) -> Unit)) -> Int +} + +fun foo(vararg x: @Foo(10) @Bar(10) @Foo(Any) (Any) -> Unit) = 10 + +fun foo(): @Foo.Bar(@Foo x) suspend (Nothing) -> Unit = {} + +fun foo(): () -> @Foo.Bar('1') suspend (Bar) -> Unit = {} + +val x: Any get() = fun(): @Foo("") (Coomparable) -> Unit {} + +fun foo() { + var x: (@Foo(object {}) (()->Unit)-> ()->Unit) -> Unit = {} +} + +fun foo(x: Any) { + if (x as @Foo({}) @Bar(10) @Foo(10) (()->Unit) -> Unit is suspend @Foo(10) @Bar(10) @Foo(10) (()->Unit) -> Unit) {} +} + +fun foo(y: Any) { + var x = y as (@Foo({}) suspend (()->Unit) -> (()->Unit) -> Unit) -> Unit +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withoutParameter.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withoutParameter.json new file mode 100644 index 000000000..5e9e16c3b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withoutParameter.json @@ -0,0 +1,604 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "@Foo() (() -> (() -> Unit)) -> Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "ABSTRACT" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "x.", + "return_type": { + "name": "(@Foo() () -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@Foo() (() -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@Foo() () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Comparable<@Fo() @Bar(10) @Foo() () -> Unit>", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo() () -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "x" + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "@Foo(10) @Bar() () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "@Foo() @Bar() () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "@Foo() () -> () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "@Foo() @Bar(10) @Foo() () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "vararg" + } + ] + } + ], + "expression": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "foo", + "return_type": { + "name": "@Foo.Bar() () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "return_type": { + "name": "() -> @Foo.Bar() () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Any", + "kind": "OTHER" + }, + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "@Foo() () -> Unit", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo() ()->()->Unit) -> Unit", + "kind": "OTHER" + }, + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK" + } + ], + "conditions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "@Foo() @Bar(10) @Foo() () -> Unit", + "kind": "OTHER" + } + } + ], + "new_type": { + "name": "@Foo() @Bar(10) @Foo() () -> Unit", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "(@Foo() () -> () -> Unit) -> Unit", + "kind": "OTHER" + } + } + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo() () -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@Foo() (() -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@Foo() () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Comparable<@Fo() @Bar(10) @Foo() () -> Unit>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "new_type": { + "name": "@Foo() () -> Unit", + "kind": "OTHER" + } + } + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withoutParameter.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withoutParameter.kt new file mode 100644 index 000000000..218ec79f2 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withParentheses/withoutParameter.kt @@ -0,0 +1,47 @@ +// Issue: KT-31734 + +val x: (@Foo() () -> Unit) get() = {} + +val x: @Foo() (() -> Unit) get() = {} + +val x: @Foo() () -> Unit get() = {} + +val x: Comparable<@Fo() @Bar(10) @Foo() () -> Unit> get() = {} + +val x: Any = {} as @Foo() () -> Unit + +fun foo(x: (@Foo() () -> Unit)) = x + +fun foo(x: @Foo(10) @Bar() () -> Unit = { x: Int -> x }) {} + +fun foo() { + val x: @Foo() @Bar() () -> Unit = {} +} + +fun foo() { + val x = { x: @Foo() () -> () -> Unit -> x } +} + +abstract class A { + abstract var x: @Foo() (() -> (() -> Unit)) -> Int +} + +fun foo(vararg x: @Foo() @Bar(10) @Foo() () -> Unit) = 10 + +fun foo(): @Foo.Bar() () -> Unit = {} + +fun foo(): () -> @Foo.Bar() () -> Unit = {} + +val x: Any get() = fun(): @Foo() () -> Unit {} + +fun foo() { + var x: (@Foo() ()->()->Unit) -> Unit = {} +} + +fun foo(x: Any) { + if (x as @Foo() @Bar(10) @Foo() () -> Unit is @Foo() @Bar(10) @Foo() () -> Unit) {} +} + +fun foo(y: Any) { + var x = y as (@Foo() () -> () -> Unit) -> Unit +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/annotationList.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/annotationList.json new file mode 100644 index 000000000..8c4b8e563 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/annotationList.json @@ -0,0 +1,658 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "@[Foo Bar] suspend (() -> ((Int) -> Unit)) -> Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "ABSTRACT" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "x.", + "return_type": { + "name": "(@[Foo] suspend (Int) -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "(@[Foo] () -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "(@[Foo] suspend () -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@[Foo] ((x: @[Foo] (@[Foo Foo] () -> Int) -> Int) -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "suspend @[Foo] (x: @[Foo Foo] (@[Foo Foo] (x: kotlin.Any) -> Int) -> Int) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Comparable<@[Foo] @[Bar(10)] @[Foo] () -> Unit>", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo ()->()->Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "x" + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "suspend @[Foo Foo(10)] @[Bar] (kotlin.Any) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "@[Foo(10)] @[Bar] (Coomparable) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "suspend @[Foo Bar] (Coomparable<@[Foo Bar Bar Bar Bar Bar] @[Bar(10)] @[Foo Bar] () -> Unit>) -> () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "@[Foo Bar] @[Bar(10)] @[Foo Bar] () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "vararg" + } + ] + } + ], + "expression": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "foo", + "return_type": { + "name": "@[Foo.Bar Foo.Bar(1)] suspend () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "return_type": { + "name": "() -> @[Foo.Bar] () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Any", + "kind": "OTHER" + }, + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "@[Foo()] (Coomparable) -> Unit", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "(@[Foo Bar] (()->Unit)-> ()->Unit) -> Unit", + "kind": "OTHER" + }, + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK" + } + ], + "conditions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "@[Foo] @[Bar(10) Bar] @[Foo Bar] (()->Unit) -> Unit", + "kind": "OTHER" + } + } + ], + "new_type": { + "name": "suspend @[Foo] @[Bar (10)] @[Foo Bar (10)] (()->Unit) -> Unit", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "(@[Foo Bar] suspend (()->Unit) -> (()->Unit) -> Unit) -> Unit", + "kind": "OTHER" + } + } + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "x", + "variable_type": { + "name": "(@[Foo] suspend (Int) -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "(@[Foo] () -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "(@[Foo] suspend () -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@[Foo] ((x: @[Foo] (@[Foo Foo] () -> Int) -> Int) -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "suspend @[Foo] (x: @[Foo Foo] (@[Foo Foo] (x: kotlin.Any) -> Int) -> Int) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Comparable<@[Foo] @[Bar(10)] @[Foo] () -> Unit>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "new_type": { + "name": "@[Foo Foo] suspend (x: @[Foo] Foo) -> (y: @[Foo] Bar) -> Unit", + "kind": "OTHER" + } + } + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/annotationList.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/annotationList.kt new file mode 100644 index 000000000..ffb4d2096 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/annotationList.kt @@ -0,0 +1,51 @@ +// Issue: KT-31734 + +val x: (@[Foo] suspend (Int) -> Unit) get() = {} + +val x: (@[Foo] () -> Unit) get() = {} + +val x: (@[Foo] suspend () -> Unit) get() = {} + +val x: @[Foo] ((x: @[Foo] (@[Foo Foo] () -> Int) -> Int) -> Unit) get() = {} + +val x: suspend @[Foo] (x: @[Foo Foo] (@[Foo Foo] (x: kotlin.Any) -> Int) -> Int) -> Unit get() = {} + +val x: Comparable<@[Foo] @[Bar(10)] @[Foo] () -> Unit> get() = {} + +val x: Any = {} as @[Foo Foo] suspend (x: @[Foo] Foo) -> (y: @[Foo] Bar) -> Unit + +fun foo(x: (@Foo ()->()->Unit)) = x + +fun foo(x: suspend @[Foo Foo(10)] @[Bar] (kotlin.Any) -> Unit = { x: Int -> x }) {} + +fun foo() { + val x: @[Foo(10)] @[Bar] (Coomparable) -> Unit = {} +} + +fun foo() { + val x = { x: suspend @[Foo Bar] (Coomparable<@[Foo Bar Bar Bar Bar Bar] @[Bar(10)] @[Foo Bar] () -> Unit>) -> () -> Unit -> x } +} + +abstract class A { + abstract var x: @[Foo Bar] suspend (() -> ((Int) -> Unit)) -> Int +} + +fun foo(vararg x: @[Foo Bar] @[Bar(10)] @[Foo Bar] () -> Unit) = 10 + +fun foo(): @[Foo.Bar Foo.Bar(1)] suspend () -> Unit = {} + +fun foo(): () -> @[Foo.Bar] () -> Unit = {} + +val x: Any get() = fun(): @[Foo()] (Coomparable) -> Unit {} + +fun foo() { + var x: (@[Foo Bar] (()->Unit)-> ()->Unit) -> Unit = {} +} + +fun foo(x: Any) { + if (x as @[Foo] @[Bar(10) Bar] @[Foo Bar] (()->Unit) -> Unit is suspend @[Foo] @[Bar (10)] @[Foo Bar (10)] (()->Unit) -> Unit) {} +} + +fun foo(y: Any) { + var x = y as (@[Foo Bar] suspend (()->Unit) -> (()->Unit) -> Unit) -> Unit +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withParameter.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withParameter.json new file mode 100644 index 000000000..61e849923 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withParameter.json @@ -0,0 +1,604 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "@Foo suspend (suspend (Int) -> ((Int) -> Unit)) -> Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "ABSTRACT" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "x.", + "return_type": { + "name": "(@Foo suspend (Int) -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@Foo ((x: @Foo (@Foo () -> Int) -> Int) -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "suspend @Foo (x: @Foo (@Foo (x: kotlin.Any) -> Int) -> Int) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Comparable<@Foo @Bar(10) @Foo (x: kotlin.Any) -> Unit>", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo (@Foo kotlin.Any)->()->Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "x" + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "suspend @Foo(10) @Bar (kotlin.Any) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "@Foo suspend @Bar (Coomparable) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "suspend @Foo (Coomparable<@Foo @Bar(10) @Foo () -> Unit>) -> () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "@Foo @Bar(10) @Foo (Any) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "vararg" + } + ] + } + ], + "expression": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "foo", + "return_type": { + "name": "@Foo.Bar suspend (Nothing) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "return_type": { + "name": "() -> @Foo.Bar suspend (Bar) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Any", + "kind": "OTHER" + }, + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "@Foo (Coomparable) -> Unit", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo (()->Unit)-> ()->Unit) -> Unit", + "kind": "OTHER" + }, + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK" + } + ], + "conditions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "@Foo @Bar(10) @Foo (()->Unit) -> Unit", + "kind": "OTHER" + } + } + ], + "new_type": { + "name": "suspend @Foo @Bar(10) @Foo (()->Unit) -> Unit", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "(@Foo suspend (()->Unit) -> (()->Unit) -> Unit) -> Unit", + "kind": "OTHER" + } + } + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo suspend (Int) -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@Foo ((x: @Foo (@Foo () -> Int) -> Int) -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "suspend @Foo (x: @Foo (@Foo (x: kotlin.Any) -> Int) -> Int) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Comparable<@Foo @Bar(10) @Foo (x: kotlin.Any) -> Unit>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "new_type": { + "name": "@Foo suspend (x: @Foo Foo) -> (y: @Foo Bar) -> Unit", + "kind": "OTHER" + } + } + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withParameter.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withParameter.kt new file mode 100644 index 000000000..c0f8ccd10 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withParameter.kt @@ -0,0 +1,47 @@ +// Issue: KT-31734 + +val x: (@Foo suspend (Int) -> Unit) get() = {} + +val x: @Foo ((x: @Foo (@Foo () -> Int) -> Int) -> Unit) get() = {} + +val x: suspend @Foo (x: @Foo (@Foo (x: kotlin.Any) -> Int) -> Int) -> Unit get() = {} + +val x: Comparable<@Foo @Bar(10) @Foo (x: kotlin.Any) -> Unit> get() = {} + +val x: Any = {} as @Foo suspend (x: @Foo Foo) -> (y: @Foo Bar) -> Unit + +fun foo(x: (@Foo (@Foo kotlin.Any)->()->Unit)) = x + +fun foo(x: suspend @Foo(10) @Bar (kotlin.Any) -> Unit = { x: Int -> x }) {} + +fun foo() { + val x: @Foo suspend @Bar (Coomparable) -> Unit = {} +} + +fun foo() { + val x = { x: suspend @Foo (Coomparable<@Foo @Bar(10) @Foo () -> Unit>) -> () -> Unit -> x } +} + +abstract class A { + abstract var x: @Foo suspend (suspend (Int) -> ((Int) -> Unit)) -> Int +} + +fun foo(vararg x: @Foo @Bar(10) @Foo (Any) -> Unit) = 10 + +fun foo(): @Foo.Bar suspend (Nothing) -> Unit = {} + +fun foo(): () -> @Foo.Bar suspend (Bar) -> Unit = {} + +val x: Any get() = fun(): @Foo (Coomparable) -> Unit {} + +fun foo() { + var x: (@Foo (()->Unit)-> ()->Unit) -> Unit = {} +} + +fun foo(x: Any) { + if (x as @Foo @Bar(10) @Foo (()->Unit) -> Unit is suspend @Foo @Bar(10) @Foo (()->Unit) -> Unit) {} +} + +fun foo(y: Any) { + var x = y as (@Foo suspend (()->Unit) -> (()->Unit) -> Unit) -> Unit +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withReveiver.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withReveiver.json new file mode 100644 index 000000000..551ce8ce6 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withReveiver.json @@ -0,0 +1,658 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "@Foo suspend (@Foo () -> Unit).(suspend (Int) -> ((Int) -> Unit)) -> Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "ABSTRACT" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "x.", + "return_type": { + "name": "(@Foo suspend Int.() -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@Foo Int.() -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@Foo Int.(x: kotlin.Int) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@Foo ((x: @Foo (@Foo () -> Int) -> Int.(@Foo () -> Int) -> Int) -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "suspend @Foo (x: @Foo (@Foo ((x: kotlin.Any) -> Int).(x: kotlin.Any) -> Int) -> Int) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Comparable<@Foo @Bar(10) @Foo Unit.(x: kotlin.Any) -> Unit>", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo ((@Foo kotlin.Any)->(Int)).(@Foo kotlin.Any)->()->Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "x" + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "suspend @Foo(10) @Bar Comparable.(kotlin.Any) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "@Foo suspend @Bar (Coomparable) -> Unit.(Coomparable) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "suspend @Foo @Foo () -> Unit.(Coomparable<@Foo @Bar(10) @Foo () -> Unit>) -> () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "@Foo @Bar(10) @Foo Any.(Any) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "vararg" + } + ] + } + ], + "expression": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "foo", + "return_type": { + "name": "@Foo.Bar suspend Nothing.(Nothing) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "return_type": { + "name": "() -> @Foo.Bar suspend Iterable<@Foo.Bar Int.(Bar) -> Unit>.(Bar) -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Any", + "kind": "OTHER" + }, + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "@Foo (@Foo (Coomparable) -> Unit).(Coomparable) -> Unit", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo (()->Unit)-> @Foo Int.()->Unit) -> Unit", + "kind": "OTHER" + }, + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK" + } + ], + "conditions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "@Foo @Bar(10) @Foo ()->Unit.(()->Unit) -> Unit", + "kind": "OTHER" + } + } + ], + "new_type": { + "name": "suspend @Foo @Bar(10) @Foo ((()->Unit).()->Unit) -> Unit", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "(@Foo suspend (suspend (()->Unit)->Int).(()->Unit) -> (Float.()->Unit) -> Unit) -> Unit", + "kind": "OTHER" + } + } + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo suspend Int.() -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@Foo Int.() -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@Foo Int.(x: kotlin.Int) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@Foo ((x: @Foo (@Foo () -> Int) -> Int.(@Foo () -> Int) -> Int) -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "suspend @Foo (x: @Foo (@Foo ((x: kotlin.Any) -> Int).(x: kotlin.Any) -> Int) -> Int) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Comparable<@Foo @Bar(10) @Foo Unit.(x: kotlin.Any) -> Unit>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "new_type": { + "name": "@Foo suspend Int.(x: @Foo Foo) -> (y: @Foo Bar) -> Unit", + "kind": "OTHER" + } + } + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withReveiver.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withReveiver.kt new file mode 100644 index 000000000..b34d6fb32 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withReveiver.kt @@ -0,0 +1,51 @@ +// Issue: KT-31734 + +val x: (@Foo suspend Int.() -> Unit) get() = {} + +val x: @Foo Int.() -> Unit get() = {} + +val x: @Foo Int.(x: kotlin.Int) -> Unit get() = {} + +val x: @Foo ((x: @Foo (@Foo () -> Int) -> Int.(@Foo () -> Int) -> Int) -> Unit) get() = {} + +val x: suspend @Foo (x: @Foo (@Foo ((x: kotlin.Any) -> Int).(x: kotlin.Any) -> Int) -> Int) -> Unit get() = {} + +val x: Comparable<@Foo @Bar(10) @Foo Unit.(x: kotlin.Any) -> Unit> get() = {} + +val x: Any = {} as @Foo suspend Int.(x: @Foo Foo) -> (y: @Foo Bar) -> Unit + +fun foo(x: (@Foo ((@Foo kotlin.Any)->(Int)).(@Foo kotlin.Any)->()->Unit)) = x + +fun foo(x: suspend @Foo(10) @Bar Comparable.(kotlin.Any) -> Unit = { x: Int -> x }) {} + +fun foo() { + val x: @Foo suspend @Bar (Coomparable) -> Unit.(Coomparable) -> Unit = {} +} + +fun foo() { + val x = { x: suspend @Foo @Foo () -> Unit.(Coomparable<@Foo @Bar(10) @Foo () -> Unit>) -> () -> Unit -> x } +} + +abstract class A { + abstract var x: @Foo suspend (@Foo () -> Unit).(suspend (Int) -> ((Int) -> Unit)) -> Int +} + +fun foo(vararg x: @Foo @Bar(10) @Foo Any.(Any) -> Unit) = 10 + +fun foo(): @Foo.Bar suspend Nothing.(Nothing) -> Unit = {} + +fun foo(): () -> @Foo.Bar suspend Iterable<@Foo.Bar Int.(Bar) -> Unit>.(Bar) -> Unit = {} + +val x: Any get() = fun(): @Foo (@Foo (Coomparable) -> Unit).(Coomparable) -> Unit {} + +fun foo() { + var x: (@Foo (()->Unit)-> @Foo Int.()->Unit) -> Unit = {} +} + +fun foo(x: Any) { + if (x as @Foo @Bar(10) @Foo ()->Unit.(()->Unit) -> Unit is suspend @Foo @Bar(10) @Foo ((()->Unit).()->Unit) -> Unit) {} +} + +fun foo(y: Any) { + var x = y as (@Foo suspend (suspend (()->Unit)->Int).(()->Unit) -> (Float.()->Unit) -> Unit) -> Unit +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameter.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameter.json new file mode 100644 index 000000000..b30c7d4b5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameter.json @@ -0,0 +1,604 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "@Foo (() -> (() -> Unit)) -> Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "ABSTRACT" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "x.", + "return_type": { + "name": "(@Foo () -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@Foo (() -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@Foo () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Comparable<@Foo @Bar(10) @Foo () -> Unit>", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo () -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "x" + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "@Foo(10) @Bar () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "@Foo @Bar () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "@Foo () -> () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "@Foo @Bar(10) @Foo () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "vararg" + } + ] + } + ], + "expression": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "foo", + "return_type": { + "name": "@Foo.Bar () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "return_type": { + "name": "() -> @Foo.Bar () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Any", + "kind": "OTHER" + }, + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "@Foo () -> Unit", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo ()->()->Unit) -> Unit", + "kind": "OTHER" + }, + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK" + } + ], + "conditions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "@Foo @Bar(10) @Foo () -> Unit", + "kind": "OTHER" + } + } + ], + "new_type": { + "name": "@Foo @Bar(10) @Foo () -> Unit", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "(@Foo () -> () -> Unit) -> Unit", + "kind": "OTHER" + } + } + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo () -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@Foo (() -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@Foo () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Comparable<@Foo @Bar(10) @Foo () -> Unit>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "new_type": { + "name": "@Foo () -> Unit", + "kind": "OTHER" + } + } + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameter.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameter.kt new file mode 100644 index 000000000..abd830465 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameter.kt @@ -0,0 +1,47 @@ +// Issue: KT-31734 + +val x: (@Foo () -> Unit) get() = {} + +val x: @Foo (() -> Unit) get() = {} + +val x: @Foo () -> Unit get() = {} + +val x: Comparable<@Foo @Bar(10) @Foo () -> Unit> get() = {} + +val x: Any = {} as @Foo () -> Unit + +fun foo(x: (@Foo () -> Unit)) = x + +fun foo(x: @Foo(10) @Bar () -> Unit = { x: Int -> x }) {} + +fun foo() { + val x: @Foo @Bar () -> Unit = {} +} + +fun foo() { + val x = { x: @Foo () -> () -> Unit -> x } +} + +abstract class A { + abstract var x: @Foo (() -> (() -> Unit)) -> Int +} + +fun foo(vararg x: @Foo @Bar(10) @Foo () -> Unit) = 10 + +fun foo(): @Foo.Bar () -> Unit = {} + +fun foo(): () -> @Foo.Bar () -> Unit = {} + +val x: Any get() = fun(): @Foo () -> Unit {} + +fun foo() { + var x: (@Foo ()->()->Unit) -> Unit = {} +} + +fun foo(x: Any) { + if (x as @Foo @Bar(10) @Foo () -> Unit is @Foo @Bar(10) @Foo () -> Unit) {} +} + +fun foo(y: Any) { + var x = y as (@Foo () -> () -> Unit) -> Unit +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameterOnSuspend.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameterOnSuspend.json new file mode 100644 index 000000000..2bf306ad9 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameterOnSuspend.json @@ -0,0 +1,604 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "@Foo suspend (suspend () -> (() -> Unit)) -> Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "ABSTRACT" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "x.", + "return_type": { + "name": "(@Foo suspend () -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "@Foo (suspend () -> Unit)", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "suspend @Foo () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Comparable<@Foo suspend @Bar(10) @Foo () -> Unit>", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "(suspend @Foo () -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "x" + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "suspend @Foo(10) @Bar () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "@Foo suspend @Bar () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "suspend @Foo () -> () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "@Foo @Bar(10) @Foo () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "vararg" + } + ] + } + ], + "expression": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "foo", + "return_type": { + "name": "@Foo.Bar suspend () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "foo", + "return_type": { + "name": "() -> @Foo.Bar suspend () -> Unit", + "kind": "OTHER" + }, + "expression": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + }, + { + "name": "x.", + "return_type": { + "name": "Any", + "kind": "OTHER" + }, + "expression": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "@Foo suspend () -> Unit", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo ()->suspend ()->Unit) -> Unit", + "kind": "OTHER" + }, + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK" + } + ], + "conditions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "@Foo @Bar(10) suspend @Foo () -> Unit", + "kind": "OTHER" + } + } + ], + "new_type": { + "name": "suspend @Foo @Bar(10) @Foo () -> Unit", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "(@Foo suspend () -> () -> Unit) -> Unit", + "kind": "OTHER" + } + } + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "x", + "variable_type": { + "name": "(@Foo suspend () -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "@Foo (suspend () -> Unit)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "suspend @Foo () -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Comparable<@Foo suspend @Bar(10) @Foo () -> Unit>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "new_type": { + "name": "@Foo suspend () -> Unit", + "kind": "OTHER" + } + } + }, + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameterOnSuspend.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameterOnSuspend.kt new file mode 100644 index 000000000..5c1883869 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/functionalTypes/withoutParentheses/withoutParameterOnSuspend.kt @@ -0,0 +1,47 @@ +// Issue: KT-31734 + +val x: (@Foo suspend () -> Unit) get() = {} + +val x: @Foo (suspend () -> Unit) get() = {} + +val x: suspend @Foo () -> Unit get() = {} + +val x: Comparable<@Foo suspend @Bar(10) @Foo () -> Unit> get() = {} + +val x: Any = {} as @Foo suspend () -> Unit + +fun foo(x: (suspend @Foo () -> Unit)) = x + +fun foo(x: suspend @Foo(10) @Bar () -> Unit = { x: Int -> x }) {} + +fun foo() { + val x: @Foo suspend @Bar () -> Unit = {} +} + +fun foo() { + val x = { x: suspend @Foo () -> () -> Unit -> x } +} + +abstract class A { + abstract var x: @Foo suspend (suspend () -> (() -> Unit)) -> Int +} + +fun foo(vararg x: @Foo @Bar(10) @Foo () -> Unit) = 10 + +fun foo(): @Foo.Bar suspend () -> Unit = {} + +fun foo(): () -> @Foo.Bar suspend () -> Unit = {} + +val x: Any get() = fun(): @Foo suspend () -> Unit {} + +fun foo() { + var x: (@Foo ()->suspend ()->Unit) -> Unit = {} +} + +fun foo(x: Any) { + if (x as @Foo @Bar(10) suspend @Foo () -> Unit is suspend @Foo @Bar(10) @Foo () -> Unit) {} +} + +fun foo(y: Any) { + var x = y as (@Foo suspend () -> () -> Unit) -> Unit +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/list/basic.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/list/basic.json new file mode 100644 index 000000000..7218631f7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/list/basic.json @@ -0,0 +1,112 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "abc", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "\"\"" + } + ] + }, + { + "kind": "ANNOTATION", + "annotation_name": "cde" + } + ], + "methods": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "abc" + }, + { + "kind": "ANNOTATION", + "annotation_name": "cde" + }, + { + "kind": "ANNOTATION", + "annotation_name": "private" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "3", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "abc" + } + ] + } + ] + } + ], + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "suppress", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "\"a\"" + } + ] + } + ] + } + ] + } + ], + "type_declarations": [ + { + "name": "Local", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "data" + }, + { + "kind": "ANNOTATION", + "annotation_name": "inline" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/list/basic.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/list/basic.kt new file mode 100644 index 000000000..fd866915f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/list/basic.kt @@ -0,0 +1,11 @@ +@[abc("") cde] +class A { + @[ abc + cde] + @[private] + fun foo() { + @[data inline] class Local {} + + @[suppress("a")] (1 + @[abc] 3) + } +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/modifiersMigration/newModifiers.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/modifiersMigration/newModifiers.json new file mode 100644 index 000000000..fb28b30ed --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/modifiersMigration/newModifiers.json @@ -0,0 +1,528 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "IMMUTABLE", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "OTHER", + "other": "data" + }, + { + "kind": "OTHER", + "other": "inline" + } + ], + "methods": [ + { + "name": "x.", + "modifiers": [ + { + "kind": "OTHER", + "other": "noinline" + } + ], + "return_type": { + "name": "Int", + "kind": "OTHER" + } + }, + { + "name": "x.", + "modifiers": [ + { + "kind": "OTHER", + "other": "inline" + }, + { + "kind": "OTHER", + "other": "data" + } + ], + "return_type": { + "name": "Unit", + "kind": "OTHER" + } + }, + { + "name": "y.", + "modifiers": [ + { + "kind": "OTHER", + "other": "inline" + } + ], + "return_type": { + "name": "String", + "kind": "OTHER" + }, + "expression": { + "kind": "LITERAL", + "literal": "1" + } + }, + { + "name": "y.", + "modifiers": [ + { + "kind": "OTHER", + "other": "data" + } + ], + "return_type": { + "name": "Unit", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "q", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "LITERAL", + "literal": "2" + } + }, + { + "name": "z.", + "modifiers": [ + { + "kind": "OTHER", + "other": "inline" + } + ], + "return_type": { + "name": "Double", + "kind": "OTHER" + } + }, + { + "name": "z.", + "modifiers": [ + { + "kind": "OTHER", + "other": "noinline" + } + ], + "return_type": { + "name": "Unit", + "kind": "OTHER" + } + }, + { + "name": "z0.", + "modifiers": [ + { + "kind": "OTHER", + "other": "inline" + } + ], + "return_type": { + "name": "Double", + "kind": "OTHER" + } + }, + { + "name": "z0.", + "modifiers": [ + { + "kind": "OTHER", + "other": "noinline" + } + ], + "return_type": { + "name": "Unit", + "kind": "OTHER" + } + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "z", + "variable_type": { + "name": "Double", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "z0", + "variable_type": { + "name": "Double", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "3.0" + } + } + ] + } + ], + "methods": [ + { + "name": "bar", + "modifiers": [ + { + "kind": "OTHER", + "other": "data" + }, + { + "kind": "OTHER", + "other": "annotation" + }, + { + "kind": "OTHER", + "other": "tailrec" + }, + { + "kind": "OTHER", + "other": "external" + }, + { + "kind": "OTHER", + "other": "noinline" + } + ], + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "data" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x1", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "noinline" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "1" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "data" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x2", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "2" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x3", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "3" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x4", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "inline" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "4" + } + } + ] + } + ] + } + ], + "methods": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "OTHER", + "other": "inline" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "type_declarations": [ + { + "name": "A", + "kind": "IMMUTABLE", + "modifiers": [ + { + "kind": "OTHER", + "other": "data" + }, + { + "kind": "OTHER", + "other": "inline" + }, + { + "kind": "OTHER", + "other": "noinline" + } + ] + }, + { + "name": "Q", + "kind": "IMMUTABLE", + "modifiers": [ + { + "kind": "ABSTRACT" + }, + { + "kind": "OTHER", + "other": "data" + } + ] + } + ] + } + ] + }, + { + "name": "foo1", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "data" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OTHER", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "inline" + }, + { + "kind": "VARACCESS", + "variable": "annotation" + } + ], + "literal": "data" + } + ] + } + ] + } + ] + }, + { + "name": "foo2", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "data", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "inline", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/modifiersMigration/newModifiers.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/modifiersMigration/newModifiers.kt new file mode 100644 index 000000000..85ae1f497 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/modifiersMigration/newModifiers.kt @@ -0,0 +1,60 @@ +data annotation tailrec external noinline fun bar(data x: Int) { + data inline noinline class A + + inline fun foo() {} + + noinline val x1 = 1 + + data(); + + val x2 = 2 + + data; + + val x3 = 3 + + inline + + + private + val x4 = 4 + + abstract + + data + + class Q +} + + +fun foo1() { + data() + + inline data annotation // infix call +} + +fun foo2() { + data { + + } + + inline(data) { + + } +} + + +public data inline class A { + val x: Int + inline data set + noinline get + + val y: String + inline get() = 1 + data set(q: Int) = 2 + + val z: Double inline get noinline set + + val z0: Double = 3.0 + inline get noinline set +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArg.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArg.json new file mode 100644 index 000000000..befff95b1 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArg.json @@ -0,0 +1,175 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Annotation", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "baz", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "bar", + "expression": { + "kind": "VARACCESS", + "variable": "x" + } + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "foo", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "annotation", + "variable_type": { + "name": "Annotation", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "annotation" + } + ], + "method": "baz" + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "annotation" + } + ], + "method": "bar" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArg.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArg.kt new file mode 100644 index 000000000..5484366ee --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArg.kt @@ -0,0 +1,14 @@ +class Annotation(val x: Int) { + fun baz() {} + fun bar() = x +} + +fun foo(annotation: Annotation): Int { + if (annotation.bar() == 0) { + annotation.baz() + return 0 + } + else { + return -1 + } +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArgComplex.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArgComplex.json new file mode 100644 index 000000000..2eb804e57 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArgComplex.json @@ -0,0 +1,103 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Annotation", + "kind": "CLASS", + "methods": [ + { + "name": "setProblemGroup", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "getQuickFixes", + "expression": { + "kind": "LITERAL", + "literal": "0" + } + } + ] + } + ], + "methods": [ + { + "name": "registerQuickFix", + "arguments": [ + { + "name": "annotation", + "variable_type": { + "name": "Annotation", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "annotation" + } + ], + "method": "setProblemGroup" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "fixes", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "annotation" + } + ], + "method": "getQuickFixes" + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArgComplex.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArgComplex.kt new file mode 100644 index 000000000..2f8aa3161 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/annotationAsArgComplex.kt @@ -0,0 +1,9 @@ +class Annotation { + fun setProblemGroup() {} + fun getQuickFixes() = 0 +} + +fun registerQuickFix(annotation: Annotation) { + annotation.setProblemGroup() + val fixes = annotation.getQuickFixes() +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/java.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/java.json new file mode 100644 index 000000000..9cece6af0 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/java.json @@ -0,0 +1,90 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "my", + "kind": "ANNOTATION", + "modifiers": [ + { + "kind": "OTHER", + "other": "annotation" + }, + { + "kind": "ANNOTATION", + "annotation_name": "java.lang.annotation.Retention", + "annotation_values": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "RetentionPolicy" + } + ], + "variable": "CLASS" + } + ] + } + ] + }, + { + "name": "my1", + "kind": "ANNOTATION", + "modifiers": [ + { + "kind": "OTHER", + "other": "annotation" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Retention", + "annotation_values": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "RetentionPolicy" + } + ], + "variable": "RUNTIME" + } + ] + }, + { + "kind": "ANNOTATION", + "annotation_name": "Target", + "annotation_values": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "ElementType" + } + ], + "variable": "ANNOTATION_TYPE" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "ElementType" + } + ], + "variable": "CONSTRUCTOR" + } + ] + } + ] + } + ], + "imports": [ + "java.lang.annotation.*" + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/java.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/java.kt new file mode 100644 index 000000000..5890b0099 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/java.kt @@ -0,0 +1,10 @@ +import java.lang.annotation.* + +annotation +@java.lang.annotation.Retention(RetentionPolicy.CLASS) +class my + +annotation +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR) +class my1 diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/local.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/local.json new file mode 100644 index 000000000..b517ef78c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/local.json @@ -0,0 +1,71 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "1" + } + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ], + "type_declarations": [ + { + "name": "Ann", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "annotation" + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/local.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/local.kt new file mode 100644 index 000000000..21c6e0b46 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/options/local.kt @@ -0,0 +1,5 @@ +fun foo(): Int { + @annotation class Ann + @Ann val x = 1 + return x +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/delegate.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/delegate.json new file mode 100644 index 000000000..c313420c6 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/delegate.json @@ -0,0 +1,78 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "fields": [ + { + "name": "plainField", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Transient", + "other": "delegate" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "1" + } + }, + { + "name": "lazy", + "variable_type": { + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "lazy", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Transient", + "other": "delegate" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/delegate.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/delegate.kt new file mode 100644 index 000000000..0b56aaeca --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/delegate.kt @@ -0,0 +1,7 @@ +class C { + @delegate:Transient + val plainField: Int = 1 + + @delegate:Transient + val lazy by lazy { 1 } +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/fqName.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/fqName.json new file mode 100644 index 000000000..8876f9795 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/fqName.json @@ -0,0 +1,32 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "fields": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "kotlin.Deprecated", + "other": "field" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"String\"" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/fqName.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/fqName.kt new file mode 100644 index 000000000..9c5fe0bda --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/fqName.kt @@ -0,0 +1,6 @@ +class A { + + @field:kotlin.Deprecated + val a = "String" + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/inWrongPlace.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/inWrongPlace.json new file mode 100644 index 000000000..00829f268 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/inWrongPlace.json @@ -0,0 +1,55 @@ +{ + "namespaces": [ + { + "name": "boo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "field" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "field" + } + ], + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "field" + } + ] + }, + { + "name": "I", + "kind": "INTERFACE", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "field" + } + ] + } + ], + "methods": [ + { + "name": "a", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "field" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/inWrongPlace.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/inWrongPlace.kt new file mode 100644 index 000000000..29f64186d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/inWrongPlace.kt @@ -0,0 +1,13 @@ +@field:Deprecated + +@field:Deprecated +package boo + +@field:Deprecated +class A + +@field:Deprecated +interface I + +@field:Deprecated +fun a() \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/manyInOneAnnotationBlock.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/manyInOneAnnotationBlock.json new file mode 100644 index 000000000..912418be3 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/manyInOneAnnotationBlock.json @@ -0,0 +1,42 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "fields": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "first", + "other": "field" + }, + { + "kind": "ANNOTATION", + "annotation_name": "second", + "other": "field" + }, + { + "kind": "ANNOTATION", + "annotation_name": "third", + "other": "field" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"String\"" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/manyInOneAnnotationBlock.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/manyInOneAnnotationBlock.kt new file mode 100644 index 000000000..697a2a28c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/manyInOneAnnotationBlock.kt @@ -0,0 +1,6 @@ +class A { + + @field:[first second third] + val a = "String" + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/simpleFieldAnnotation.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/simpleFieldAnnotation.json new file mode 100644 index 000000000..797dcd295 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/simpleFieldAnnotation.json @@ -0,0 +1,32 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "fields": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "field" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"String\"" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/simpleFieldAnnotation.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/simpleFieldAnnotation.kt new file mode 100644 index 000000000..17210a883 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onField/simpleFieldAnnotation.kt @@ -0,0 +1,6 @@ +class A { + + @field:Deprecated + val a = "String" + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyAnnotationBlocks.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyAnnotationBlocks.json new file mode 100644 index 000000000..7ae7c0866 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyAnnotationBlocks.json @@ -0,0 +1,24 @@ +{ + "namespaces": [ + { + "name": "bar", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "foo", + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "bar", + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "baz", + "other": "file" + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyAnnotationBlocks.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyAnnotationBlocks.kt new file mode 100644 index 000000000..fff50bd92 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyAnnotationBlocks.kt @@ -0,0 +1,3 @@ +@file:foo +@file:[bar baz] +package bar diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyInOneAnnotationBlock.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyInOneAnnotationBlock.json new file mode 100644 index 000000000..7ae7c0866 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyInOneAnnotationBlock.json @@ -0,0 +1,24 @@ +{ + "namespaces": [ + { + "name": "bar", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "foo", + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "bar", + "other": "file" + }, + { + "kind": "ANNOTATION", + "annotation_name": "baz", + "other": "file" + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyInOneAnnotationBlock.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyInOneAnnotationBlock.kt new file mode 100644 index 000000000..e890bc66d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/manyInOneAnnotationBlock.kt @@ -0,0 +1,2 @@ +@file: [foo bar baz] +package bar diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/single.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/single.json new file mode 100644 index 000000000..3585c97bb --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/single.json @@ -0,0 +1,14 @@ +{ + "namespaces": [ + { + "name": "bar", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "foo", + "other": "file" + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/single.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/single.kt new file mode 100644 index 000000000..37019a40a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/single.kt @@ -0,0 +1,2 @@ +@file:foo +package bar diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutFileAnnotationAndPackageDeclaration.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutFileAnnotationAndPackageDeclaration.json new file mode 100644 index 000000000..7eaa5d1a8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutFileAnnotationAndPackageDeclaration.json @@ -0,0 +1,38 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "ann", + "kind": "ANNOTATION", + "modifiers": [ + { + "kind": "OTHER", + "other": "annotation" + } + ] + } + ], + "methods": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "ann" + } + ], + "return_type": { + "name": "String?", + "kind": "OTHER" + }, + "expression": { + "kind": "LITERAL", + "literal": "null" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutFileAnnotationAndPackageDeclaration.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutFileAnnotationAndPackageDeclaration.kt new file mode 100644 index 000000000..e81933189 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutFileAnnotationAndPackageDeclaration.kt @@ -0,0 +1,3 @@ +@ann fun foo(): String? = null + +annotation class ann diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackage.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackage.json new file mode 100644 index 000000000..cb3194c45 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackage.json @@ -0,0 +1,39 @@ +{ + "namespaces": [ + { + "name": "", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "foo", + "other": "file" + } + ], + "methods": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "foo" + }, + { + "kind": "ANNOTATION", + "annotation_name": "bar" + }, + { + "kind": "ANNOTATION", + "annotation_name": "baz", + "other": "file" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackage.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackage.kt new file mode 100644 index 000000000..b4f7712d1 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackage.kt @@ -0,0 +1,4 @@ +@file:foo +@foo @bar +@file:[baz] +fun foo() {} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackageWithSimpleAnnotation.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackageWithSimpleAnnotation.json new file mode 100644 index 000000000..cb3194c45 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackageWithSimpleAnnotation.json @@ -0,0 +1,39 @@ +{ + "namespaces": [ + { + "name": "", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "foo", + "other": "file" + } + ], + "methods": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "foo" + }, + { + "kind": "ANNOTATION", + "annotation_name": "bar" + }, + { + "kind": "ANNOTATION", + "annotation_name": "baz", + "other": "file" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackageWithSimpleAnnotation.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackageWithSimpleAnnotation.kt new file mode 100644 index 000000000..a2cace035 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onFile/withoutPackageWithSimpleAnnotation.kt @@ -0,0 +1,4 @@ +@file:foo +@foo @bar +@file: baz +fun foo() {} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/inWrongPlace.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/inWrongPlace.json new file mode 100644 index 000000000..25fab0e35 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/inWrongPlace.json @@ -0,0 +1,126 @@ +{ + "namespaces": [ + { + "name": "boo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "get" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "set" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "setparam" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "get" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "set" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "setparam" + } + ], + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "get" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "set" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "setparam" + } + ] + }, + { + "name": "I", + "kind": "INTERFACE", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "get" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "set" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "setparam" + } + ] + } + ], + "methods": [ + { + "name": "a", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "get" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "set" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "setparam" + } + ] + }, + { + "name": "b", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "get" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "set" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Deprecated", + "other": "setparam" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/inWrongPlace.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/inWrongPlace.kt new file mode 100644 index 000000000..29f9c99d9 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/inWrongPlace.kt @@ -0,0 +1,28 @@ +@get:Deprecated +@set:Deprecated +@setparam:Deprecated + +@get:Deprecated +@set:Deprecated +@setparam:Deprecated +package boo + +@get:Deprecated +@set:Deprecated +@setparam:Deprecated +class A + +@get:Deprecated +@set:Deprecated +@setparam:Deprecated +interface I + +@get:Deprecated +@set:Deprecated +@setparam:Deprecated +fun a() + +@get:Deprecated +@set:Deprecated +@setparam:Deprecated +fun b() \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/simple.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/simple.json new file mode 100644 index 000000000..473634772 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/simple.json @@ -0,0 +1,43 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "fields": [ + { + "name": "a", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "An", + "other": "get" + }, + { + "kind": "ANNOTATION", + "annotation_name": "An", + "other": "set" + }, + { + "kind": "ANNOTATION", + "annotation_name": "An", + "other": "setparam" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"A\"" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/simple.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/simple.kt new file mode 100644 index 000000000..94bf798cb --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/simple.kt @@ -0,0 +1,8 @@ +class A { + + @get:An + @set:An + @setparam:An + var a: String = "A" + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/twoAnnotationLists.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/twoAnnotationLists.json new file mode 100644 index 000000000..0d9d6060d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/twoAnnotationLists.json @@ -0,0 +1,103 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "methods": [ + { + "name": "a.", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "e" + } + ], + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "LITERAL", + "literal": "5" + } + }, + { + "name": "a.", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "f" + }, + { + "kind": "ANNOTATION", + "annotation_name": "g" + } + ], + "return_type": { + "name": "Unit", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "v", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "h" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "fields": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "a", + "other": "get" + }, + { + "kind": "ANNOTATION", + "annotation_name": "b", + "other": "set" + }, + { + "kind": "ANNOTATION", + "annotation_name": "c", + "other": "set" + }, + { + "kind": "ANNOTATION", + "annotation_name": "d", + "other": "setparam" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/twoAnnotationLists.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/twoAnnotationLists.kt new file mode 100644 index 000000000..9f0e611c0 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onGetSetSparam/twoAnnotationLists.kt @@ -0,0 +1,10 @@ +class A { + + @get:a + @set:[b c] + @setparam:d + var a: Int + @e get() = 5 + @f @g set(@h v) {} + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/modifiers.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/modifiers.json new file mode 100644 index 000000000..6006b43ed --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/modifiers.json @@ -0,0 +1,94 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "value", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "param" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "param" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "value", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "param" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "param" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/modifiers.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/modifiers.kt new file mode 100644 index 000000000..90044e12f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/modifiers.kt @@ -0,0 +1 @@ +public class A(public @param:Ann private @param:[Ann] val value: String) \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/simple.json b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/simple.json new file mode 100644 index 000000000..7582c1fd2 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/simple.json @@ -0,0 +1,121 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "value", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "param" + } + ] + } + ] + } + ] + }, + { + "name": "B", + "kind": "CLASS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "n", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "param" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann2", + "other": "param" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "n", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "other": "param" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann2", + "other": "param" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/simple.kt b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/simple.kt new file mode 100644 index 000000000..c8836bddb --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/annotation/targeted/onParam/simple.kt @@ -0,0 +1,3 @@ +public class A(@param:Ann value: String) + +public class B(@param:[Ann Ann2] val n: Int) \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/destructuringInLambdas.json b/test/datagen/kotlin/kotlin-compiler-tests/destructuringInLambdas.json new file mode 100644 index 000000000..1dec1deaa --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/destructuringInLambdas.json @@ -0,0 +1,470 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a1" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a2" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a3" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "z", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a4" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "z", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a5" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "q", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "z", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a6" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "z", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "w", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a7" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "z", + "variable_type": { + "name": "Type", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "w", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "u", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "foo7" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/destructuringInLambdas.kt b/test/datagen/kotlin/kotlin-compiler-tests/destructuringInLambdas.kt new file mode 100644 index 000000000..ca21a67de --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/destructuringInLambdas.kt @@ -0,0 +1,10 @@ +fun foo() { + a1.filter { (x, y) -> } + a2.filter { (x) -> } + a3.filter { z, (x, y) -> } + a4.filter { (x, y), z -> } + a5.filter { q, (x, y), z -> } + a6.filter { (x, y), (z, w) -> } + + a7.filter { (x, y): Type, (z: Type), (w, u: T) : V -> foo7() } +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/AnonymousObjects.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/AnonymousObjects.json new file mode 100644 index 000000000..8bc008d0f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/AnonymousObjects.json @@ -0,0 +1,270 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "addMouseListener", + "method_args": [ + { + "kind": "NEW", + "new_type": { + "name": "MouseAdapter", + "kind": "CLASS" + }, + "anon_declaration": { + "name": "", + "kind": "SINGLETON", + "parents": [ + { + "name": "MouseAdapter", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "mouseClicked", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "e", + "variable_type": { + "name": "MouseEvent", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_INC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "clickCount" + } + ], + "is_postfix": true + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "GOD" + } + ], + "method": "sendMessage", + "method_args": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "GodMEssages" + } + ], + "variable": "TOO_MANY_CLICKS" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "clickCount" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "clickCount", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "0" + } + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "GOD", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "NEW", + "anon_declaration": { + "name": "", + "kind": "SINGLETON", + "methods": [ + { + "name": "sendMessage", + "arguments": [ + { + "name": "message", + "variable_type": { + "name": "GodMEssage", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "RuntimeException", + "method_args": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "message" + } + ], + "variable": "name" + } + ] + } + ] + } + ] + } + } + ] + } + } + } + ] + } + ] + } + ], + "type_declarations": [ + { + "name": "GodMessages", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "fields": [ + { + "name": "TOO_MANY_CLICKS", + "variable_type": { + "name": "GodMessages", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + }, + { + "name": "ONE_MORE_MESSAGE", + "variable_type": { + "name": "GodMessages", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/AnonymousObjects.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/AnonymousObjects.kt new file mode 100644 index 000000000..c4bbceb7f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/AnonymousObjects.kt @@ -0,0 +1,23 @@ +fun foo() { + +addMouseListener(object : MouseAdapter() { + + private var clickCount = 0; + + override fun mouseClicked(e : MouseEvent) { + clickCount++; + if (clickCount > 3) GOD.sendMessage(GodMEssages.TOO_MANY_CLICKS); + } +}) + +enum class GodMessages { + TOO_MANY_CLICKS, + ONE_MORE_MESSAGE +} + +// Type of this variable is GOD_AnonymousClass +val GOD = object { + fun sendMessage(message : GodMEssage) = throw RuntimeException(message.name) +}; + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/BitArith.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/BitArith.json new file mode 100644 index 000000000..ec6415f14 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/BitArith.json @@ -0,0 +1,733 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "INumber", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "parents": [ + { + "name": "IComparable", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "plus", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Operator" + } + ], + "return_type": { + "name": "This", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "other", + "variable_type": { + "name": "This", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "shl", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Operator" + } + ], + "return_type": { + "name": "This", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "bits", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "bits", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "oneBit", + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "BIT_LSHIFT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + }, + { + "name": "setBit", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "BIT_OR", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "METHODCALL", + "method": "oneBit", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + } + }, + { + "name": "unsetBit", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "BIT_AND", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "METHODCALL", + "method": "not", + "method_args": [ + { + "kind": "METHODCALL", + "method": "oneBit", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + } + ] + } + }, + { + "name": "getBit", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "NEQ", + "expressions": [ + { + "kind": "BIT_AND", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "METHODCALL", + "method": "oneBit", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + }, + { + "name": "getBit", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "NEQ", + "expressions": [ + { + "kind": "BIT_LSHIFT", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "BIT_RSHIFT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + }, + { + "kind": "LITERAL", + "literal": "31" + } + ] + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + }, + { + "name": "countOnes", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "INumber", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "result", + "initializer": { + "kind": "LITERAL", + "literal": "0" + } + } + ] + } + ] + }, + { + "kind": "WHILE", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + }, + { + "kind": "BIT_AND", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "BIT_UNSIGNEDRSHIFT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "NEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + } + ] + } + ] + } + ] + }, + { + "name": "mostSignificantBit", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "INumber", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "CAST", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "NEQ", + "expressions": [ + { + "kind": "BIT_AND", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "METHODCALL", + "method": "oneBit", + "method_args": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "variable": "bits" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ], + "new_type": { + "name": "Int", + "kind": "OTHER" + } + } + }, + { + "name": "countOnes", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "INumber", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "0" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "METHODCALL", + "method": "mostSignificantBit", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + }, + { + "kind": "METHODCALL", + "method": "countOnes", + "method_args": [ + { + "kind": "BIT_LSHIFT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + }, + { + "name": "matchMask", + "arguments": [ + { + "name": "mask", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "EQ", + "expressions": [ + { + "kind": "BIT_AND", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "VARACCESS", + "variable": "mask" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "mask" + } + ] + }, + "receiver_type": { + "name": "Int", + "kind": "OTHER" + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/BitArith.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/BitArith.kt new file mode 100644 index 000000000..7fbe10d02 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/BitArith.kt @@ -0,0 +1,33 @@ +fun oneBit(index : Int) = 1 shl index + +fun setBit(x : Int, index : Int) = x or oneBit(index) +fun unsetBit(x : Int, index : Int) = x and not(oneBit(index)) + +fun getBit(x : Int, index : Int) = x and oneBit(index) != 0 +fun getBit(x : Int, index : Int) = (x shr index) shl 31 != 0 + +fun countOnes(x : INumber) { + var result = 0 + while (x != 0) { + result += x and 1 + x = x ushr 1 + } + result +} + +fun mostSignificantBit(x : INumber) = (x and oneBit(x.bits - 1) != 0) as Int + +fun countOnes(x : INumber) = if (x == 0) 0 else mostSignificantBit(x) + countOnes(x shl 1) + +fun Int.matchMask(mask : Int) = this and mask == mask + +open class INumber : IComparable { + val bits : Int + + @Operator + fun plus(other : This) : This + + @Operator + fun shl(bits : Int) : This + // ... +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/Builder.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/Builder.json new file mode 100644 index 000000000..70b2557c7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/Builder.json @@ -0,0 +1,506 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "AntBuilder", + "kind": "CLASS", + "methods": [ + { + "name": "library", + "arguments": [ + { + "name": "initializer", + "variable_type": { + "name": "Library.() -> Library", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "lib", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "Library" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "lib" + } + ], + "method": "initializer" + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "lib" + } + ] + } + ] + } + ] + }, + { + "name": "classpath" + }, + { + "name": "module" + } + ], + "nested_declarations": [ + { + "name": "ClassPathEntry", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ] + }, + { + "name": "Module", + "kind": "CLASS", + "parents": [ + { + "name": "ClassPathEntry", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "classpath", + "arguments": [ + { + "name": "entries", + "variable_type": { + "name": "ClassPathEntry", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "src", + "arguments": [ + { + "name": "src", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "fields": [ + { + "name": "targetLevel", + "variable_type": { + "name": "String", + "kind": "OTHER" + } + } + ] + }, + { + "name": "Library", + "kind": "CLASS", + "parents": [ + { + "name": "ClassPathEntry", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "classpath", + "arguments": [ + { + "name": "entries", + "variable_type": { + "name": "ClassPathEntry", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "NEW", + "new_type": { + "name": "AntBuilder", + "kind": "CLASS" + }, + "anon_declaration": { + "name": "", + "kind": "SINGLETON", + "parents": [ + { + "name": "AntBuilder", + "kind": "CLASS" + } + ], + "fields": [ + { + "name": "groovy", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "lazy" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "library", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "classpath", + "method_args": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "libs" + } + ], + "literal": "\"$libs\"" + }, + { + "kind": "TEMPLATE", + "literal": "\"/groovy-...\"" + } + ], + "literal": "\"$libs/groovy-...\"" + } + ] + } + ] + } + ] + } + ] + } + ] + } + }, + { + "name": "gant", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "lazy" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "library", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHODCALL", + "method": "File", + "method_args": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "gantHome" + } + ], + "literal": "\"$gantHome\"" + }, + { + "kind": "TEMPLATE", + "literal": "\"/lib\"" + } + ], + "literal": "\"$gantHome/lib\"" + } + ] + } + ], + "variable": "files" + } + ], + "method": "each", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "classpath", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "it" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + }, + { + "name": "JPS", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "ANNOTATION", + "annotation_name": "lazy" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "module", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "targetLevel" + }, + { + "kind": "LITERAL", + "literal": "\"1.5\"" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "classpath", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "antLayout" + }, + { + "kind": "VARACCESS", + "variable": "gant" + }, + { + "kind": "VARACCESS", + "variable": "groovy" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "src", + "method_args": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "projectHome" + } + ], + "literal": "\"$projectHome\"" + }, + { + "kind": "TEMPLATE", + "literal": "\"/antLayout/src\"" + } + ], + "literal": "\"$projectHome/antLayout/src\"" + } + ] + } + ] + } + ] + } + ] + } + ] + } + } + ] + } + } + ], + "method": "build" + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/Builder.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/Builder.kt new file mode 100644 index 000000000..b7cc2ad54 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/Builder.kt @@ -0,0 +1,43 @@ +val foo = object : AntBuilder() { + + @lazy val groovy = library { + classpath("$libs/groovy-...") + } + + @lazy val gant = library { + File("$gantHome/lib").files.each { + classpath(it) + } + } + + @lazy val JPS = module { + targetLevel = "1.5" + classpath(antLayout, gant, groovy) + src("$projectHome/antLayout/src") + } + +}.build() + +class AntBuilder { + abstract class ClassPathEntry {} + + class Module : ClassPathEntry { + fun classpath(entries : ClassPathEntry/*...*/) { /*...*/ } + var targetLevel : String + fun src(src : String) { /*...*/ } + } + + class Library : ClassPathEntry { + fun classpath(entries : ClassPathEntry/*...*/) { /*...*/ } + } + + fun library(initializer : Library.() -> Library) { + val lib = Library() + lib.initializer() + return lib + } + + fun classpath(/*...*/) + + fun module(/*...*/) +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/Color.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/Color.json new file mode 100644 index 000000000..5d5a160e7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/Color.json @@ -0,0 +1,229 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Color", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "r", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "g", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "sb", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "r", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "g", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "sb", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "RED", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "255" + }, + { + "kind": "LITERAL", + "literal": "0" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + }, + { + "name": "GREEN", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0" + }, + { + "kind": "LITERAL", + "literal": "255" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + }, + { + "name": "BLUE", + "variable_type": { + "name": "Color", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0" + }, + { + "kind": "LITERAL", + "literal": "0" + }, + { + "kind": "LITERAL", + "literal": "255" + } + ] + } + ], + "new_type": { + "name": "Color", + "kind": "ENUM" + } + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/Color.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/Color.kt new file mode 100644 index 000000000..64b844520 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/Color.kt @@ -0,0 +1,5 @@ +enum class Color(val r : Int, val g : Int, val sb : Int) { + RED(255, 0, 0), + GREEN(0, 255, 0), + BLUE(0, 0, 255) +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/FunctionsAndTypes.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/FunctionsAndTypes.json new file mode 100644 index 000000000..9a9537127 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/FunctionsAndTypes.json @@ -0,0 +1,206 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f1", + "return_type": { + "name": "X", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "t", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "METHODCALL", + "method": "something", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "t" + } + ] + } + } + ], + "variables": [ + { + "name": "f1", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "t", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "something", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "t" + } + ] + } + ] + } + ] + } + ] + } + }, + { + "name": "f1", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "t", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "something", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "t" + } + ] + } + ] + } + ] + } + ] + } + }, + { + "name": "f1", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "something", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "it" + } + ] + } + ] + } + ] + } + ] + } + }, + { + "name": "f1", + "variable_type": { + "name": "(T) -> X", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "X" + } + ] + } + ] + } + ] + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/FunctionsAndTypes.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/FunctionsAndTypes.kt new file mode 100644 index 000000000..5fad1d04d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/FunctionsAndTypes.kt @@ -0,0 +1,8 @@ +fun f1(t : T) : X = something(t) + +val f1 = {t : T -> something(t)} +val f1 = {t -> something(t)} +val f1 = {something(it)} + +val f1 : (T) -> X = {X()} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/Graph.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/Graph.json new file mode 100644 index 000000000..140b37184 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/Graph.json @@ -0,0 +1,1080 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Vertex", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "V", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "data", + "variable_type": { + "name": "V", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "data", + "variable_type": { + "name": "V", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "Edge", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "V", + "kind": "GENERIC" + }, + { + "name": "E", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "from", + "variable_type": { + "name": "V", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "data", + "variable_type": { + "name": "E", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "to", + "variable_type": { + "name": "V", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "from", + "variable_type": { + "name": "V", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "data", + "variable_type": { + "name": "E", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "to", + "variable_type": { + "name": "V", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "Graph", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "V", + "kind": "GENERIC" + }, + { + "name": "E", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "addEdge", + "arguments": [ + { + "name": "from", + "variable_type": { + "name": "V", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "data", + "variable_type": { + "name": "E", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "to", + "variable_type": { + "name": "V", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "mutableEdges" + } + ], + "method": "add", + "method_args": [ + { + "kind": "METHODCALL", + "method": "Edge", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "from" + }, + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "to" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "addVertex", + "arguments": [ + { + "name": "v", + "variable_type": { + "name": "V", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "mutableEdges" + } + ], + "method": "add", + "method_args": [ + { + "kind": "METHODCALL", + "method": "Edge", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "from" + }, + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "to" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "neighbours", + "arguments": [ + { + "name": "v", + "variable_type": { + "name": "Vertex", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "edges" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "it" + } + ], + "variable": "from" + }, + { + "kind": "VARACCESS", + "variable": "v" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ], + "method": "map", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "it" + } + ], + "variable": "to" + } + ] + } + ] + } + ] + } + ] + } + }, + { + "name": "dfs", + "arguments": [ + { + "name": "handler", + "variable_type": { + "name": "(V) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "visited", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "Vertex", + "kind": "GENERIC" + } + ], + "method": "HashSet" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "vertices" + } + ], + "method": "foreach", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "dfs", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "it" + }, + { + "kind": "VARACCESS", + "variable": "visited" + }, + { + "kind": "VARACCESS", + "variable": "handler" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ], + "methods": [ + { + "name": "dfs", + "arguments": [ + { + "name": "current", + "variable_type": { + "name": "Vertex", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "visited", + "variable_type": { + "name": "ISet>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "handler", + "variable_type": { + "name": "(V) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "RETURN" + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "visited" + } + ], + "method": "add", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "handler", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "method": "neighbours", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ] + } + ], + "method": "foreach", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "dfs", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "it" + }, + { + "kind": "VARACCESS", + "variable": "visited" + }, + { + "kind": "VARACCESS", + "variable": "handler" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "traverse", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + } + ], + "arguments": [ + { + "name": "pending", + "variable_type": { + "name": "IPushPop>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "visited", + "variable_type": { + "name": "ISet>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "handler", + "variable_type": { + "name": "(V) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "vertices" + } + ], + "method": "foreach", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "CONTINUE" + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "visited" + } + ], + "method": "add", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "it" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "pending" + } + ], + "method": "push", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "it" + } + ] + } + ] + }, + { + "kind": "WHILE", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "current", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "pending" + } + ], + "method": "pop" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "handler", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "method": "neighbours", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ] + } + ], + "method": "foreach", + "method_args": [ + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "n", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "pending" + } + ], + "method": "push", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "n" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "visited" + } + ], + "method": "add", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "n" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "pending" + } + ], + "variable": "isEmpty" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "mutableEdges", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "Edge", + "kind": "GENERIC" + } + ], + "method": "ArrayList" + } + }, + { + "name": "mutableVertices", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "Vertex", + "kind": "GENERIC" + } + ], + "method": "HashSet" + } + }, + { + "name": "edges", + "variable_type": { + "name": "IList>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "mutableEdges" + } + }, + { + "name": "vertices", + "variable_type": { + "name": "ISet>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "mutableVertices" + } + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/Graph.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/Graph.kt new file mode 100644 index 000000000..6999b00c7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/Graph.kt @@ -0,0 +1,60 @@ +class Vertex(val data : V) + +class Edge(val from : V, val data : E, val to : V) + +class Graph { + + private val mutableEdges = ArrayList>() // type is ArrayList, but I want IMutableList +/* options: + private val edges : IMutableList> = ArrayList>() + private val edges : IMutableList> = ArrayList() // not an erasure, but a request to infer parameters +*/ + + private val mutableVertices = HashSet>() + + val edges : IList> = mutableEdges; + val vertices : ISet> = mutableVertices; + + fun addEdge(from : V, data : E, to : V) { + mutableEdges.add(Edge(from, data, to)) // constructor parameters are inferred + } + fun addVertex(v : V) { + mutableEdges.add(Edge(from, data, to)) // constructor parameters are inferred + } + + fun neighbours(v : Vertex) = edges.filter{it.from == v}.map{it.to} // type is IIterable> + + fun dfs(handler : (V) -> Unit) { + val visited = HashSet>() + vertices.foreach{dfs(it, visited, handler)} + + fun dfs(current : Vertex, visited : ISet>, handler : (V) -> Unit) { + if (!visited.add(current)) + return + handler(current) + neighbours(current).foreach{dfs(it, visited, handler)} + } + } + + public fun traverse(pending : IPushPop>, visited : ISet>, handler : (V) -> Unit) { + vertices.foreach { + if (!visited.add(it)) + continue + pending.push(it) + while (!pending.isEmpty) { + val current = pending.pop() + handler(current); + neighbours(current).foreach { n -> + if (visited.add(n)) { + pending.push(n) + } + } + /* alternative + pending->push(neighbours(current).filter{n => !visited[n])}) + // -> means that if push(x : T) and actual parameter y is IIterable, this compiles into + y.foreach{ n => push(n) } + */ + } + } + } +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/IPushPop.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/IPushPop.json new file mode 100644 index 000000000..1eb3a7b00 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/IPushPop.json @@ -0,0 +1,68 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IPushPop", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "push", + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "pop", + "return_type": { + "name": "T", + "kind": "OTHER" + } + } + ], + "fields": [ + { + "name": "isEmpty", + "variable_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/IPushPop.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/IPushPop.kt new file mode 100644 index 000000000..84725423f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/IPushPop.kt @@ -0,0 +1,5 @@ +open class IPushPop { + val isEmpty : Boolean + fun push(item : T) + fun pop() : T +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/LINQ.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/LINQ.json new file mode 100644 index 000000000..a4cf99cf0 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/LINQ.json @@ -0,0 +1,149 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OTHER", + "expressions": [ + { + "kind": "OTHER", + "expressions": [ + { + "kind": "OTHER", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "l" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "it" + } + ], + "variable": "x" + } + ] + } + ] + } + ] + } + ], + "literal": "filter" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "it" + } + ], + "variable": "foo" + } + ] + } + ] + } + ] + } + ], + "literal": "map" + }, + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + ] + } + ] + } + ] + } + ], + "literal": "aggregate" + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/LINQ.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/LINQ.kt new file mode 100644 index 000000000..b4479750b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/LINQ.kt @@ -0,0 +1,3 @@ +fun foo() { + l filter {it.x} map {it.foo} aggregate {a, b -> a + b} +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/Queue.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/Queue.json new file mode 100644 index 000000000..0b451903f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/Queue.json @@ -0,0 +1,489 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Queue", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IPushPop", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "push", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "i", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "Item", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ] + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "head" + }, + { + "kind": "VARACCESS", + "variable": "i" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + }, + { + "kind": "VARACCESS", + "variable": "head" + } + ] + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + } + ], + "variable": "next" + }, + { + "kind": "VARACCESS", + "variable": "i" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + }, + { + "kind": "VARACCESS", + "variable": "i" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + }, + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "pop", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "expression": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "UnderflowException" + } + ] + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "result", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "head" + } + ], + "variable": "data" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "head" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "head" + } + ], + "variable": "next" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + }, + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "head" + }, + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "head" + }, + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + ] + } + ] + } + }, + { + "name": "isEmpty.", + "expression": { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "head" + }, + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + } + ], + "fields": [ + { + "name": "head", + "variable_type": { + "name": "Item", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "null" + } + }, + { + "name": "tail", + "variable_type": { + "name": "Item", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "null" + } + }, + { + "name": "isEmpty", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + } + ], + "nested_declarations": [ + { + "name": "Item", + "kind": "CLASS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "data", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "next", + "variable_type": { + "name": "Item", + "kind": "OTHER" + } + } + ] + } + ], + "fields": [ + { + "name": "data", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "next", + "variable_type": { + "name": "Item", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/Queue.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/Queue.kt new file mode 100644 index 000000000..cec38da4f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/Queue.kt @@ -0,0 +1,33 @@ +class Queue : IPushPop { + private class Item(val data : T, var next : Item) + + private var head : Item = null + private var tail : Item = null + + override fun push(item : T) { + val i = Item(item) + if (tail == null) { + head = i + tail = head + } else { + tail.next = i + tail = i + } + } + + override fun pop() = + if (head == null) + throw UnderflowException() + else { + val result = head.data + head = head.next + if (head == null) + tail = null + result + } + + override val isEmpty + get() = head == null + + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/Stack.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/Stack.json new file mode 100644 index 000000000..98dc2f79a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/Stack.json @@ -0,0 +1,150 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Stack", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IPushPop", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "push", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "method": "add", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "pop", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "method": "removeLast" + } + }, + { + "name": "isEmpty.", + "expression": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "variable": "isEmpty" + } + } + ], + "fields": [ + { + "name": "data", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "method": "ArrayList" + } + }, + { + "name": "isEmpty", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/Stack.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/Stack.kt new file mode 100644 index 000000000..2929c5aa3 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/Stack.kt @@ -0,0 +1,13 @@ +class Stack : IPushPop { + private val data = ArrayList(); + + override fun push(item : T) { + data.add(item) // Problem: I would like to write push(...) = data.add(...), but the types do not match + } + + override fun pop() = data.removeLast() + + override val isEmpty + get() = data.isEmpty + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/UnionFind.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/UnionFind.json new file mode 100644 index 000000000..12a333aa2 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/UnionFind.json @@ -0,0 +1,509 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "UnionFind", + "kind": "CLASS", + "methods": [ + { + "name": "add", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "size", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "variable": "size" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "method": "add", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "size" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "size" + } + ] + } + ] + } + ] + }, + { + "name": "parent", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "p", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "p" + }, + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "result", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "parent", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "p" + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "x" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "result" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "union", + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "pa", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "parent", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "pb", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "parent", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "pb" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "pa" + } + ] + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "pa" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "pb" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Random" + } + ], + "method": "nextInt" + } + ], + "variable": "isOdd" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "NEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "pa" + }, + { + "kind": "VARACCESS", + "variable": "pb" + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "data", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "Int", + "kind": "GENERIC" + } + ], + "method": "IMutableList" + } + } + ] + } + ], + "methods": [ + { + "name": "Int.isOdd.", + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "expression": { + "kind": "NEQ", + "expressions": [ + { + "kind": "OP_MOD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/UnionFind.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/UnionFind.kt new file mode 100644 index 000000000..917d724d9 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/UnionFind.kt @@ -0,0 +1,33 @@ +class UnionFind { + private val data = IMutableList() + + fun add() : Int { + val size = data.size + data.add(size) + size + } + + private fun parent(x : Int) : Int { + val p = data[x]; + if (p == x) { + return x; + } + val result = parent(p); + data[x] = result; + } + + fun union(a : Int, b : Int) { + val pa = parent(a) + val pb = parent(b) + if (pa != pb) { + if (Random.nextInt().isOdd) { + data[pb] = pa + } else { + data[pa] = pb + } + } + } +} + +val Int.isOdd : Boolean + get() = this % 2 != 0 diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/UpdateOperation.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/UpdateOperation.json new file mode 100644 index 000000000..3fb273f14 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/UpdateOperation.json @@ -0,0 +1,285 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Pair", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "nested_declarations": [ + { + "name": "Companion", + "kind": "SINGLETON", + "modifiers": [ + { + "kind": "OTHER", + "other": "COMPANION" + }, + { + "kind": "OTHER", + "other": "companion" + } + ], + "methods": [ + { + "name": "copy", + "arguments": [ + { + "name": "from", + "variable_type": { + "name": "Pair", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "from" + } + ], + "variable": "x" + } + }, + { + "name": "y", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "from" + } + ], + "variable": "y" + } + } + ], + "expression": { + "kind": "METHODCALL", + "method": "Pair", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + } + ] + } + ] + } + ], + "variables": [ + { + "name": "p", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "Point", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + }, + { + "name": "p1", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Point" + } + ], + "method": "Copy", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "p" + }, + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + }, + { + "name": "p2", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Point" + } + ], + "method": "Copy", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "p1" + }, + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + }, + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + }, + { + "name": "p3", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Point" + } + ], + "method": "Copy", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "p" + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/UpdateOperation.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/UpdateOperation.kt new file mode 100644 index 000000000..4c3ce1d1a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/UpdateOperation.kt @@ -0,0 +1,14 @@ +class Pair(x : Int, y : Int) { + companion object { + fun copy(from : Pair, x : Int = from.x, y : Int = from.y) = Pair(x, y) + } +} + +// One can say: +val p = Point(1, 2) +val p1 = Point.Copy(p, x = 2) +val p2 = Point.Copy(p1, y = -1) +val p3 = Point.Copy(p) + +// Such copy(...) methods can be automatically generated by the compiler +// whenever there is a primary constructor \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/With.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/With.json new file mode 100644 index 000000000..13cad5d12 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/With.json @@ -0,0 +1,211 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "with", + "modifiers": [ + { + "kind": "OTHER", + "other": "inline" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "receiver", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "body", + "variable_type": { + "name": "T.() -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "receiver" + } + ], + "method": "body" + } + }, + { + "name": "example", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "with", + "method_args": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "java" + } + ], + "variable": "lang" + } + ], + "variable": "System" + } + ], + "variable": "out" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"foo\"" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"bar\"" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"foo\"" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"bar\"" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "System" + } + ], + "variable": "out" + } + ], + "method": "" + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/With.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/With.kt new file mode 100644 index 000000000..34740e838 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/With.kt @@ -0,0 +1,15 @@ +inline fun with(receiver : T, body : T.() -> Unit) = receiver.body() + +fun example() { + + with(java.lang.System.out) { + println("foo"); + print("bar"); + } + + System.out.{ + println("foo"); + print("bar"); + }() + +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/array/MutableArray.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/array/MutableArray.json new file mode 100644 index 000000000..f4c489b5a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/array/MutableArray.json @@ -0,0 +1,148 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "ReadOnlyArray", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "out T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "ISized", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "get", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "operator" + } + ], + "return_type": { + "name": "T", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "WriteOnlyArray", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "in T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "ISized", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "set", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "operator" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "value", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "MutableArray", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "ReadOnlyArray", + "kind": "CLASS" + }, + { + "name": "WriteOnlyArray", + "kind": "CLASS" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/array/MutableArray.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/array/MutableArray.kt new file mode 100644 index 000000000..48184aa7b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/array/MutableArray.kt @@ -0,0 +1,13 @@ +/** + These declarations are "shallow" in the sense that they are not really compiled, only the type-checker uses them +*/ + +open class ReadOnlyArray : ISized { + @[operator] fun get(index : Int) : T +} + +open class WriteOnlyArray : ISized { // This is needed to keep IIterator's covariant + @[operator] fun set(index : Int, value : T) +} + +class MutableArray : ReadOnlyArray, WriteOnlyArray {/*...*/} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ArrayList.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ArrayList.json new file mode 100644 index 000000000..314b0bf6d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ArrayList.json @@ -0,0 +1,1123 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "ArrayList", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IMutableList", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "iterator", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "IIterator", + "kind": "OTHER" + }, + "expression": { + "kind": "METHODCALL", + "method": "mutableIterator" + } + }, + { + "name": "mutableIterator", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "IMutableIterator", + "kind": "OTHER" + }, + "expression": { + "kind": "NEW", + "new_type": { + "name": "IMutableIterator", + "kind": "CLASS" + }, + "anon_declaration": { + "name": "", + "kind": "SINGLETON", + "parents": [ + { + "name": "IMutableIterator", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "checkVersion", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "ConcurrentModificationException" + } + ] + } + ], + "conditions": [ + { + "kind": "NEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "version" + }, + { + "kind": "VARACCESS", + "variable": "myVersion" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "next", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "checkVersion" + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "NoMoreElementsException" + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "hasNext" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "OP_INC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ], + "is_postfix": true + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "hasNext.", + "expression": { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "index" + }, + { + "kind": "VARACCESS", + "variable": "used" + } + ] + } + }, + { + "name": "remove", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "checkVersion" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "result", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "ArrayList" + } + ], + "variable": "this" + } + ], + "method": "remove", + "method_args": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "index" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "myVersion" + }, + { + "kind": "VARACCESS", + "variable": "version" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "index", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "0" + } + }, + { + "name": "myVersion", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "VARACCESS", + "variable": "version" + } + }, + { + "name": "hasNext", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + } + ] + } + } + }, + { + "name": "get", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "checkIndex", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "checkIndex", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "IndexOutOfBoundsException", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "index" + }, + { + "kind": "VARACCESS", + "variable": "used" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "isEmpty.", + "expression": { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "used" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + }, + { + "name": "size.", + "expression": { + "kind": "VARACCESS", + "variable": "used" + } + }, + { + "name": "set", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "value", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "checkIndex", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "result", + "initializer": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "index" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "value" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + } + ] + } + ] + } + ] + }, + { + "name": "add", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "value", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "ensureSize", + "method_args": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "used" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "OP_INC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "used" + } + ], + "is_postfix": true + } + ] + }, + { + "kind": "VARACCESS", + "variable": "value" + } + ] + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "i" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "i" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "used" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "index" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "value" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_INC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "used" + } + ], + "is_postfix": true + } + ] + } + ] + }, + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "IndexOutOfBoundsException", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "index" + }, + { + "kind": "VARACCESS", + "variable": "used" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "index" + }, + { + "kind": "VARACCESS", + "variable": "used" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "remove", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "i" + } + ] + }, + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "i" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "index" + }, + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "used" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "data", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "MutableArray", + "method_args": [ + { + "kind": "LITERAL", + "literal": "10" + } + ] + } + }, + { + "name": "used", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "0" + } + }, + { + "name": "version", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "0" + } + }, + { + "name": "isEmpty", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + }, + { + "name": "size", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ArrayList.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ArrayList.kt new file mode 100644 index 000000000..b42dbd9c7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ArrayList.kt @@ -0,0 +1,77 @@ +class ArrayList : IMutableList { + private var data = MutableArray(10) + private var used = 0 + private var version = 0 + + override fun iterator() : IIterator = mutableIterator() + + override fun mutableIterator() : IMutableIterator = object : IMutableIterator() { // T is inferred + private val index = 0 + private var myVersion = version + + private fun checkVersion() { + if (version != myVersion) + throw ConcurrentModificationException() + } + + override fun next() { + checkVersion() + if (hasNext) + throw NoMoreElementsException() + data[index++] + } + + override val hasNext + get() = index < used + + + override fun remove() { + checkVersion() + val result = ArrayList.this.remove(index - 1) + myVersion = version + result + } + } + + override fun get(index : Int) { + checkIndex(index) + data[index] + } + + private fun checkIndex(index : Int) { + if (index > used) + throw IndexOutOfBoundsException(index) + } + + override val isEmpty + get() = used == 0 + + + override val size + get() = used + + + override fun set(index : Int, value : T) { + checkIndex(index) + var result = data[index] + data[index] = value + result + } + + override fun add(index : Int, value : T) { + ensureSize(used + 1) + if (index == used) { + data[used++] = value + } else if (index < used) { + for (i in used-1..index) // backwards, special operator... Need to optimize this to be a real indexed loop + data[i + 1] = data[i] + data[index] = value + used++ + } else throw IndexOutOfBoundsException(index) + } + + override fun remove(index : Int) { + for (i in index..used-1) + data[i] = data[i + 1] + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/HashMap.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/HashMap.json new file mode 100644 index 000000000..784fe767c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/HashMap.json @@ -0,0 +1,870 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IEquality", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "methods": [ + { + "name": "equals", + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "other", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + } + ], + "new_type": { + "name": "java.lang.Object", + "kind": "OTHER" + } + } + ] + } + ], + "method": "equals", + "method_args": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "other" + } + ], + "new_type": { + "name": "java.lang.Object", + "kind": "OTHER" + } + } + ] + } + } + ] + }, + { + "name": "IHashable", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "parents": [ + { + "name": "IEquality", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "hashCode.", + "return_type": { + "name": "Integer", + "kind": "OTHER" + }, + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + } + ], + "new_type": { + "name": "java.lang.Object", + "kind": "OTHER" + } + } + ] + } + ], + "method": "hashCode" + } + } + ], + "fields": [ + { + "name": "hashCode", + "variable_type": { + "name": "Integer", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "IMap", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "K", + "kind": "GENERIC" + }, + { + "name": "V", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "get", + "return_type": { + "name": "V", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "key", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "set", + "return_type": { + "name": "V", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "key", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "value", + "variable_type": { + "name": "V", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "remove", + "return_type": { + "name": "V", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "key", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "containsKey", + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "key", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "HashableWrapper", + "kind": "CLASS", + "parents": [ + { + "name": "IHashable", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "obj", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "obj", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "IHashingStrategy", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "K", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "equals", + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "hashCode", + "return_type": { + "name": "Integer", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "DefaultHashingStrategy", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "in K : IHashable", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IHashingStrategy", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "equals", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "equals", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + }, + { + "name": "hashCode", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "Integer", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "variable": "hashCode" + } + } + ] + }, + { + "name": "JavaObjectHashingStrategy", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "K", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IHashingStrategy", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "equals", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "hashable" + } + ], + "method": "equals", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + }, + { + "name": "hashCode", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "Integer", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "hashable" + } + ], + "variable": "hashCode" + } + } + ] + }, + { + "name": "HashMap", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "K", + "kind": "GENERIC" + }, + { + "name": "V", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IMap", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "hashCode", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "ANNOTATION", + "annotation_name": "inline" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "hashable" + } + ], + "variable": "hashCode" + } + }, + { + "name": "equals", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "ANNOTATION", + "annotation_name": "inline" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "K", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "EQ", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "hashable" + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + } + ] + }, + { + "name": "StrategyHashMap", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "K", + "kind": "GENERIC" + }, + { + "name": "V", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IMap", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "hashingStrategy", + "variable_type": { + "name": "IHashingStrategy", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ], + "methods": [ + { + "name": "hashable", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "inline" + } + ], + "return_type": { + "name": "HashableWrapper", + "kind": "OTHER" + }, + "expression": { + "kind": "METHODCALL", + "method": "HashableWrapper", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "this" + } + ] + }, + "receiver_type": { + "name": "Any", + "kind": "OTHER" + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/HashMap.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/HashMap.kt new file mode 100644 index 000000000..f8a01c071 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/HashMap.kt @@ -0,0 +1,58 @@ +open class IEquality { + fun equals(other : Any) : Boolean + = (this as java.lang.Object).equals(other as java.lang.Object) +} + +open class IHashable : IEquality { + val hashCode : Integer + get() = (this as java.lang.Object).hashCode() + +} + +open class IMap { + fun get(key : K) : V + fun set(key : K, value : V) : V + fun remove(key : K) : V + fun containsKey(key : K) : Boolean +} + +class HashableWrapper(val obj : Any) : IHashable + // equals and hashCode implementations are inherited + +@[inline] fun Any.hashable() : HashableWrapper = HashableWrapper(this) + +open class IHashingStrategy { + fun equals(a : K, b : K) : Boolean + fun hashCode(a : K) : Integer +} + +class DefaultHashingStrategy : IHashingStrategy { + override fun equals(a : K, b : K) : Boolean = a.equals(b) + override fun hashCode(a : K) : Integer = a.hashCode +} + +class JavaObjectHashingStrategy : IHashingStrategy { + override fun equals(a : K, b : K) : Boolean + = a.hashable().equals(b) + override fun hashCode(a : K) : Integer + = a.hashable().hashCode +} + +class HashMap : IMap { + private @[inline] fun hashCode(a : K) = a.hashable().hashCode + private @[inline] fun equals(a : K, b : K) = a.hashable() == b + + // everything else uses these equals() and hashCode()... + +} + +class StrategyHashMap(hashingStrategy : IHashingStrategy) : IMap { + + + // where !(K : IHashable) + //this() : this(JavaObjectHashingStrategy()) {} + + //this() where (K : IHashable) : this(DefaultHashingStrategy()) {} + //... + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterable.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterable.json new file mode 100644 index 000000000..0bf53bebd --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterable.json @@ -0,0 +1,34 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IIterable", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "out T", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "iterator", + "return_type": { + "name": "IIterator", + "kind": "OTHER" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterable.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterable.kt new file mode 100644 index 000000000..c9a55af40 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterable.kt @@ -0,0 +1,3 @@ +open class IIterable { + fun iterator() : IIterator +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterator.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterator.json new file mode 100644 index 000000000..51e85bc70 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterator.json @@ -0,0 +1,457 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IIterator", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "out T", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "next", + "return_type": { + "name": "T", + "kind": "OTHER" + } + }, + { + "name": "toArray", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "buffer", + "variable_type": { + "name": "MutableArray", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "METHODCALL", + "method": "fillBuffer", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "buffer" + }, + { + "kind": "LITERAL", + "literal": "0" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "buffer" + } + ], + "variable": "size" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "toArray", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "buffer", + "variable_type": { + "name": "MutableArray", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "from", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "length", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "IndexOutOfBoundsException" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_OR", + "expressions": [ + { + "kind": "LOGICAL_OR", + "expressions": [ + { + "kind": "LOGICAL_OR", + "expressions": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "from" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + }, + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "from" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "buffer" + } + ], + "variable": "lastIndex" + } + ] + } + ] + }, + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "length" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + }, + { + "kind": "GT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "length" + }, + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "buffer" + } + ], + "variable": "size" + }, + { + "kind": "VARACCESS", + "variable": "from" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "len" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "count", + "initializer": { + "kind": "LITERAL", + "literal": "0" + } + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "count" + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "hasNext" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "buffer" + }, + { + "kind": "VARACCESS", + "variable": "i" + } + ] + }, + { + "kind": "METHODCALL", + "method": "next" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_INC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "count" + } + ], + "is_postfix": true + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "from" + }, + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "from" + }, + { + "kind": "VARACCESS", + "variable": "length" + } + ] + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "count" + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "hasNext", + "variable_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterator.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterator.kt new file mode 100644 index 000000000..1739eae7a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IIterator.kt @@ -0,0 +1,25 @@ +open class IIterator { + fun next() : T + val hasNext : Boolean + + fun toArray(buffer : MutableArray) : Int { // T is still an in-parameter + return fillBuffer(buffer, 0, buffer.size) + } + + fun toArray(buffer : MutableArray, from : Int, length : Int) : Int { // T is still an in-parameter + if (from < 0 || from > buffer.lastIndex || length < 0 || length > buffer.size - from) { + throw IndexOutOfBoundsException(); + } + + if (len == 0) return 0 + + var count = 0; + for (i in from .. from + length - 1) { + if (!hasNext) + return count + buffer[i] = next() + count++ + } + return count + } +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IList.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IList.json new file mode 100644 index 000000000..dcb9769b8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IList.json @@ -0,0 +1,81 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IList", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "out T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IIterable", + "kind": "CLASS" + }, + { + "name": "ISized", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "get", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "operator" + } + ], + "return_type": { + "name": "T", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "isEmpty", + "variable_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IList.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IList.kt new file mode 100644 index 000000000..a211b8186 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IList.kt @@ -0,0 +1,4 @@ +open class IList : IIterable, ISized { + @[operator] fun get(index : Int) : T + val isEmpty : Boolean +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterable.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterable.json new file mode 100644 index 000000000..644a8e9aa --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterable.json @@ -0,0 +1,40 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IMutableIterable", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "out T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IIterable", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "mutableIterator", + "return_type": { + "name": "IMutableIterator", + "kind": "OTHER" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterable.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterable.kt new file mode 100644 index 000000000..1ad49e2ae --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterable.kt @@ -0,0 +1,3 @@ +open class IMutableIterable : IIterable { + fun mutableIterator() : IMutableIterator +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterator.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterator.json new file mode 100644 index 000000000..b4549b936 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterator.json @@ -0,0 +1,40 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IMutableIterator", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "out T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IIterator", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "remove", + "return_type": { + "name": "T", + "kind": "OTHER" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterator.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterator.kt new file mode 100644 index 000000000..1449ab40d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableIterator.kt @@ -0,0 +1,13 @@ +open class IMutableIterator : IIterator { + fun remove() : T + +/* + Considerations: + pro: why not + non iteration breaking + con: counter-intuitive for, e.g., TreeSet + + + fun addBefore(item : T) : Boolean + fun addAfter(item : T) : Boolean +*/ +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableList.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableList.json new file mode 100644 index 000000000..84dfdd78f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableList.json @@ -0,0 +1,143 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IMutableList", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IList", + "kind": "CLASS" + }, + { + "name": "IMutableIterable", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "set", + "return_type": { + "name": "T", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "value", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "add", + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "value", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "remove", + "return_type": { + "name": "T", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "mutableIterator", + "return_type": { + "name": "IMutableIterator", + "kind": "OTHER" + } + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableList.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableList.kt new file mode 100644 index 000000000..55fd048e7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableList.kt @@ -0,0 +1,6 @@ +open class IMutableList : IList, IMutableIterable { + fun set(index : Int, value : T) : T + fun add(index : Int, value : T) + fun remove(index : Int) : T + fun mutableIterator() : IMutableIterator +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableSet.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableSet.json new file mode 100644 index 000000000..6b5c1e3f1 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableSet.json @@ -0,0 +1,85 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IMutableSet", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "ISet", + "kind": "CLASS" + }, + { + "name": "IMutableIterable", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "add", + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "remove", + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableSet.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableSet.kt new file mode 100644 index 000000000..95eb05d24 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/IMutableSet.kt @@ -0,0 +1,4 @@ +open class IMutableSet : ISet, IMutableIterable { + fun add(item : T) : Boolean + fun remove(item : T) : Boolean +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISet.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISet.json new file mode 100644 index 000000000..3eb17ba93 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISet.json @@ -0,0 +1,61 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "ISet", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IIterable", + "kind": "CLASS" + }, + { + "name": "ISized", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "contains", + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISet.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISet.kt new file mode 100644 index 000000000..0b6741470 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISet.kt @@ -0,0 +1,3 @@ +open class ISet : IIterable, ISized { + fun contains(item : T) : Boolean +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISized.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISized.json new file mode 100644 index 000000000..d510bfec9 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISized.json @@ -0,0 +1,33 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "ISized", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "fields": [ + { + "name": "size", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISized.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISized.kt new file mode 100644 index 000000000..5e5977f25 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/ISized.kt @@ -0,0 +1,3 @@ +open class ISized { + val size : Int +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/LinkedList.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/LinkedList.json new file mode 100644 index 000000000..3bc2c7458 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/LinkedList.json @@ -0,0 +1,1200 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "LinkedList", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IMutableList", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "size." + }, + { + "name": "size.", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "return_type": { + "name": "Unit", + "kind": "OTHER" + } + }, + { + "name": "add", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "value", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_INC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "size" + } + ], + "is_postfix": true + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "checkIndex", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "newItem", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "Item", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "value" + } + ] + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "newItem" + } + ], + "variable": "next" + }, + { + "kind": "VARACCESS", + "variable": "head" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "head" + }, + { + "kind": "VARACCESS", + "variable": "newItem" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + }, + { + "kind": "VARACCESS", + "variable": "head" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "SHEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + }, + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "insertAfter", + "initializer": { + "kind": "METHODCALL", + "method": "itemAt", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "newItem" + } + ], + "variable": "next" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "insertAfter" + } + ], + "variable": "next" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "insertAfter" + } + ], + "variable": "next" + }, + { + "kind": "VARACCESS", + "variable": "newItem" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + }, + { + "kind": "VARACCESS", + "variable": "newItem" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "SHEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + }, + { + "kind": "VARACCESS", + "variable": "insertAfter" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "index" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "checkIndex", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "IndexOutOfBoundsException", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "NOT_IN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "index" + }, + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "0" + }, + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "size" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "remove", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "T", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "checkIndex", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "item", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "itemAt", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "head" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ], + "variable": "next" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + }, + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "SHEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "head" + }, + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ], + "variable": "previous" + } + ], + "variable": "next" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ], + "variable": "next" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ], + "variable": "next" + } + ], + "variable": "previous" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ], + "variable": "previous" + } + ] + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "tail" + } + ], + "variable": "previous" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "SHEQ", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ], + "variable": "next" + }, + { + "kind": "LITERAL", + "literal": "null" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "SHEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "item" + }, + { + "kind": "VARACCESS", + "variable": "head" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_DEC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "size" + } + ], + "is_postfix": true + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ], + "variable": "value" + } + ] + } + ] + } + ] + }, + { + "name": "set", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "T", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "value", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "checkIndex", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "item", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "itemAt", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "result", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ], + "variable": "value" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ], + "variable": "value" + }, + { + "kind": "VARACCESS", + "variable": "value" + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + } + ] + } + ] + } + ] + }, + { + "name": "itemAt", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "result", + "initializer": { + "kind": "VARACCESS", + "variable": "head" + } + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + } + ], + "variable": "next" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "VARACCESS", + "variable": "index" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + } + ] + } + ] + } + ] + }, + { + "name": "mutableIterator", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "IMutableIterator", + "kind": "OTHER" + } + } + ], + "fields": [ + { + "name": "head", + "variable_type": { + "name": "Item", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "null" + } + }, + { + "name": "tail", + "variable_type": { + "name": "Item", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "null" + } + }, + { + "name": "size", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ] + } + ], + "nested_declarations": [ + { + "name": "Item", + "kind": "CLASS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "value", + "variable_type": { + "name": "Item", + "kind": "OTHER" + } + } + ] + } + ], + "fields": [ + { + "name": "value", + "variable_type": { + "name": "Item", + "kind": "OTHER" + } + }, + { + "name": "next", + "variable_type": { + "name": "Item", + "kind": "OTHER" + } + }, + { + "name": "previous", + "variable_type": { + "name": "Item", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/LinkedList.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/LinkedList.kt new file mode 100644 index 000000000..9519bcefb --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/collections/LinkedList.kt @@ -0,0 +1,73 @@ +class LinkedList : IMutableList { + private class Item(var value : Item) { + var next : Item + var previous : Item + } + + private var head : Item = null + private var tail : Item = null + override var size get private set + + override fun add(index : Int, value : T) { + size++ + checkIndex(index) + val newItem = Item(value) + if (index == 0) { + newItem.next = head + head = newItem + if (tail === null) { + tail = head + } + } else { + var insertAfter = itemAt(index) + newItem.next = insertAfter.next + insertAfter.next = newItem + if (tail === insertAfter) { + tail = newItem + } + } + } + + private fun checkIndex(index : Int) { + if (index !in 0..size-1) { + throw IndexOutOfBoundsException(index) + } + } + + override fun remove(index : Int) : T { + checkIndex(index) + val item = itemAt(index) + if (item === head) { + head = item.next + if (head === null) + tail= null + } else { + item.previous.next = item.next + if (item.next === null) { + item.next.previous = item.previous + } else { + tail = tail.previous + } + } + size-- + return item.value + } + + override fun set(index : Int, value : T) : T { + checkIndex(index) + val item = itemAt(index) + val result = item.value + item.value = value + return result + } + + private fun itemAt(index : Int) { + var result = head + for (i in 1..index) { + result = result.next + } + return result + } + + override fun mutableIterator() : IMutableIterator +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/io/IOSamples.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/io/IOSamples.json new file mode 100644 index 000000000..e89625421 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/io/IOSamples.json @@ -0,0 +1,656 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IAdder", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "in T", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "add", + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "ICloseable", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "methods": [ + { + "name": "close" + } + ] + }, + { + "name": "JavaCloseableWrapper", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ABSTRACT" + } + ], + "parents": [ + { + "name": "ICloseable", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "closeable", + "variable_type": { + "name": "java.io.Closeable", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "ICloseable", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "closeable" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "FileInput", + "kind": "CLASS", + "parents": [ + { + "name": "IIterator", + "kind": "CLASS" + }, + { + "name": "JavaCloseableWrapper", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "next", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "nextUsed" + }, + { + "kind": "LITERAL", + "literal": "true" + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "next" + } + ], + "new_type": { + "name": "Byte", + "kind": "OTHER" + } + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "nextUsed" + } + ] + } + ] + }, + { + "kind": "RETURN" + } + ] + } + ] + }, + { + "name": "hasNext.", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "nextUsed" + }, + { + "kind": "LITERAL", + "literal": "false" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "next" + }, + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "stream" + } + ], + "method": "read" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_AND", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "nextUsed" + }, + { + "kind": "NEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "next" + }, + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "NEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "next" + }, + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "stream", + "variable_type": { + "name": "InputStream", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + }, + { + "name": "next", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + }, + { + "name": "nextUsed", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "false" + } + }, + { + "name": "hasNext", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + } + ] + }, + { + "name": "FileOutput", + "kind": "CLASS", + "parents": [ + { + "name": "IAdder", + "kind": "CLASS" + }, + { + "name": "JavaCloseableWrapper", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "add", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "Byte", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "stream" + } + ], + "method": "write", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "stream", + "variable_type": { + "name": "OutputStream", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "streamCopy", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "from", + "variable_type": { + "name": "IIterable", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "to", + "variable_type": { + "name": "IAdder", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "t" + } + ], + "method": "add", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "VARACCESS", + "variable": "from" + } + ], + "variable_declarations": [ + { + "name": "item", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "example", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "f1", + "variable_type": { + "name": "File", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "f2", + "variable_type": { + "name": "File", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "streamCopy", + "method_args": [ + { + "kind": "METHODCALL", + "method": "FileInput", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "f1" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "f2" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/io/IOSamples.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/io/IOSamples.kt new file mode 100644 index 000000000..06c12de61 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/io/IOSamples.kt @@ -0,0 +1,62 @@ +open class IAdder { + fun add(item : T) : Boolean +} + +open class ICloseable { + fun close() +} + +abstract class JavaCloseableWrapper(closeable : java.io.Closeable) : ICloseable(closeable) + +fun streamCopy(from : IIterable, to : IAdder) { + for (item in from) t.add(item) +} + +class FileInput : IIterator, JavaCloseableWrapper { + private val stream : InputStream + private var next : Int + private var nextUsed = false + + //this(file : File) : JavaCloseableWrapper(stream) { // implicitly throws IOException + // stream = FileInputStream(file) // throws IOException + //} + + override fun next() { + if (!nextUsed) { + nextUsed = true + return next as Byte + } + return + } + + override val hasNext + get() { // implicitly throws IOException + if (nextUsed && next != -1) { + nextUsed = false + next = stream.read() // throws IOException + } + return next != -1 + } + +} + +class FileOutput : IAdder, JavaCloseableWrapper { + private val stream : OutputStream + + //this(file : File) : JavaCloseableWrapper(stream) { + // stream = FileOutputStream(file) + //} + + override fun add(item : Byte) { + stream.write(item) + } +} + +fun example() { // this does not rethrow, no appropriate parameters given + + val f1 : File //= ... + val f2 : File //= ... + + streamCopy(FileInput(f1), f2) // throws IOException, you must catch or rethrow explicitly + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/map/IMap.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/map/IMap.json new file mode 100644 index 000000000..01090f09a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/map/IMap.json @@ -0,0 +1,29 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IMap", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "in K", + "kind": "GENERIC" + }, + { + "name": "out V", + "kind": "GENERIC" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/map/IMap.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/map/IMap.kt new file mode 100644 index 000000000..da51189c0 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/map/IMap.kt @@ -0,0 +1,4 @@ +open class IMap { + + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/BinaryHeap.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/BinaryHeap.json new file mode 100644 index 000000000..6017e7627 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/BinaryHeap.json @@ -0,0 +1,1200 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "BinaryHeap", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IPriorityQueue", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "extract", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "return_type": { + "name": "T", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "UnderflowException" + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + } + ], + "variable": "isEmpty" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "method": "swap", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "variable": "lastIndex" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "method": "remove", + "method_args": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "variable": "lastIndex" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "siftDown", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "add", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "method": "add", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "siftUp", + "method_args": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "variable": "lastItem" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "siftDown", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "current", + "initializer": { + "kind": "VARACCESS", + "variable": "index" + } + } + ] + } + ] + }, + { + "kind": "WHILE", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "min", + "initializer": { + "kind": "VARACCESS", + "variable": "current" + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "min" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "left" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "left" + } + ], + "variable": "value" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "min" + } + ], + "variable": "value" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "min" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "right" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_AND", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "right" + } + ], + "variable": "exists" + }, + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "right" + } + ], + "variable": "value" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "min" + } + ], + "variable": "value" + } + ] + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "BREAK" + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "min" + }, + { + "kind": "VARACCESS", + "variable": "current" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "method": "swap", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "min" + }, + { + "kind": "VARACCESS", + "variable": "current" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + }, + { + "kind": "VARACCESS", + "variable": "min" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "left" + } + ], + "variable": "exists" + } + ] + } + ] + } + ] + }, + { + "name": "siftUp", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "arguments": [ + { + "name": "index", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "RETURN" + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "exists" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "current", + "initializer": { + "kind": "VARACCESS", + "variable": "index" + } + } + ] + } + ] + }, + { + "kind": "WHILE", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "method": "swap", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "current" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "parent" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "parent" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "value" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "parent" + } + ], + "variable": "value" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "current" + } + ], + "variable": "parent" + } + ], + "variable": "exists" + } + ] + } + ] + } + ] + }, + { + "name": "Int.parent.", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "OP_DIV", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + }, + { + "name": "Int.left.", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "OP_MULT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + }, + { + "name": "Int.right.", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "OP_MULT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + }, + { + "name": "Int.value.", + "return_type": { + "name": "T", + "kind": "OTHER" + }, + "expression": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + }, + { + "kind": "VARACCESS", + "variable": "this" + } + ] + } + }, + { + "name": "Int.value.", + "return_type": { + "name": "Unit", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "it", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "field" + }, + { + "kind": "VARACCESS", + "variable": "it" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "Int.exists.", + "return_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "expression": { + "kind": "LOGICAL_AND", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "data" + } + ], + "variable": "size" + } + ] + } + ] + }, + { + "kind": "PAREN", + "expressions": [ + { + "kind": "GTEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + } + ] + } + }, + { + "name": "compareTo", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "other", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "METHODCALL", + "method": "compare", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "VARACCESS", + "variable": "other" + } + ] + }, + "receiver_type": { + "name": "T", + "kind": "OTHER" + } + } + ], + "fields": [ + { + "name": "data", + "variable_type": { + "name": "IMutableList", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + }, + { + "name": "compare", + "variable_type": { + "name": "Comparison", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "swap", + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "t", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "VARACCESS", + "variable": "a" + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + }, + { + "kind": "VARACCESS", + "variable": "t" + } + ] + } + ] + } + ] + } + ], + "receiver_type": { + "name": "IMutableList", + "kind": "OTHER" + } + }, + { + "name": "IList.lastIndex.", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "this" + } + ], + "variable": "size" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/BinaryHeap.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/BinaryHeap.kt new file mode 100644 index 000000000..b39a11ad9 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/BinaryHeap.kt @@ -0,0 +1,101 @@ +class BinaryHeap : IPriorityQueue { + private val data : IMutableList + private val compare : Comparison + +// this(data : IIterable, compare : Comparison = naturalOrder) { +// this.compare = compare +// this.data = ArrayList(data) +//// siftDown(* this.data.size / 2 .. 0) +// +// for (val i in data.size / 2 .. 0) { +// siftDown(i) +// } +// +// } + + //this(compare : Comparison) { + // this.compare = compare + // this.data = ArrayList() + //} + // + //this() { + // this.data = ArrayList() + // Assert(T is IComparable) + // this.comparator = naturalOrder + //} + + override fun extract() : T { + if (this.isEmpty) + throw UnderflowException() + data.swap(0, data.lastIndex) + data.remove(data.lastIndex) + siftDown(0) + } + + override fun add(item : T) { + data.add(item) + siftUp(data.lastItem) + } + + private fun siftDown(index : Int) { + var current = index + while (current.left.exists) { + var min = current + if (current.left.value < min.value) { + min = current.left + } + if (current.right.exists && current.right.value < min.value) { + min = current.right + } + if (min == current) break + data.swap(min, current) + current = min + } + } + + private fun siftUp(index : Int) { + if (!current.exists) return + var current = index + while (current.parent.exists) { + if (current.value < current.parent.value) { + data.swap(current, current.parent) + current = current.parent + } + } + } + + val Int.parent : Int + get() = (this - 1) / 2 + + + val Int.left : Int + get() = this * 2 + 1 + + + val Int.right : Int + get() = this * 2 + 2 + + + val Int.value : T + get() = data[this] + set(it) { + field = it + } + + + val Int.exists : Boolean + get() = (this < data.size) && (this >= 0) + + fun T.compareTo(other : T) : Int = compare(this, other) + +} + +fun IMutableList.swap(a : Int, b : Int) { + val t = this[a] + this[a] = this[b] + this[b] = t +} + +val IList.lastIndex : Int + get() = this.size - 1 + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/IPriorityQueue.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/IPriorityQueue.json new file mode 100644 index 000000000..4154230b3 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/IPriorityQueue.json @@ -0,0 +1,68 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IPriorityQueue", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "extract", + "return_type": { + "name": "T", + "kind": "OTHER" + } + }, + { + "name": "add", + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "isEmpty", + "variable_type": { + "name": "Boolean", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/IPriorityQueue.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/IPriorityQueue.kt new file mode 100644 index 000000000..ee694f5c9 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/IPriorityQueue.kt @@ -0,0 +1,5 @@ +open class IPriorityQueue { + fun extract() : T + fun add(item : T) + val isEmpty : Boolean +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/PriorityQueueAsPushPop.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/PriorityQueueAsPushPop.json new file mode 100644 index 000000000..e8fb3ac83 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/PriorityQueueAsPushPop.json @@ -0,0 +1,142 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "PriorityQueueAsPushPop", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "IPushPop", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "wrapped", + "variable_type": { + "name": "IPriorityQueue", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "pop", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "wrapped" + } + ], + "method": "extract" + } + }, + { + "name": "push", + "modifiers": [ + { + "kind": "OTHER", + "other": "override" + } + ], + "arguments": [ + { + "name": "item", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "wrapped" + } + ], + "method": "add", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "item" + } + ] + } + }, + { + "name": "isEmpty.", + "expression": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "wrapped" + } + ], + "variable": "isEmpty" + } + } + ], + "fields": [ + { + "name": "isEmpty", + "modifiers": [ + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "override" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/PriorityQueueAsPushPop.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/PriorityQueueAsPushPop.kt new file mode 100644 index 000000000..86f317b79 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/priorityqueues/PriorityQueueAsPushPop.kt @@ -0,0 +1,7 @@ +class PriorityQueueAsPushPop(wrapped : IPriorityQueue) : IPushPop { + override fun pop() = wrapped.extract() + override fun push(item : T) = wrapped.add(item) + override val isEmpty + get() = wrapped.isEmpty + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/util/Comparison.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/util/Comparison.json new file mode 100644 index 000000000..ca64c2aed --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/util/Comparison.json @@ -0,0 +1,379 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "ComparisonResult", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "fields": [ + { + "name": "LS", + "variable_type": { + "name": "ComparisonResult", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + }, + { + "name": "EQ", + "variable_type": { + "name": "ComparisonResult", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + }, + { + "name": "GR", + "variable_type": { + "name": "ComparisonResult", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + } + ] + } + ], + "methods": [ + { + "name": "naturalOrder", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "in T : Comparable", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "method": "compareTo", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + }, + { + "name": "castingNaturalOrder", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "Object", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "Object", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ], + "new_type": { + "name": "Comparable", + "kind": "OTHER" + } + } + ] + } + ], + "method": "compareTo", + "method_args": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "b" + } + ], + "new_type": { + "name": "Comparable", + "kind": "OTHER" + } + } + ] + } + }, + { + "name": "asMatchableComparison", + "return_type": { + "name": "MatchableComparison", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "cmp", + "variable_type": { + "name": "Comparison", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "a", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "res", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "cmp", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "a" + }, + { + "kind": "VARACCESS", + "variable": "b" + } + ] + } + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "ComparisonResult" + } + ], + "variable": "EQ" + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "res" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + }, + { + "kind": "IF", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "ComparisonResult" + } + ], + "variable": "LS" + } + ] + } + ], + "conditions": [ + { + "kind": "LT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "res" + }, + { + "kind": "LITERAL", + "literal": "0" + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "ComparisonResult" + } + ], + "variable": "GR" + } + ] + } + ] + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/util/Comparison.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/util/Comparison.kt new file mode 100644 index 000000000..51e349563 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/util/Comparison.kt @@ -0,0 +1,15 @@ +fun naturalOrder>(a : T, b : T) : Int = a.compareTo(b) + +fun castingNaturalOrder(a : Object, b : Object) : Int = (a as Comparable).compareTo(b as Comparable) + +enum class ComparisonResult { + LS, EQ, GR; +} + +fun asMatchableComparison(cmp : Comparison) : MatchableComparison = {a, b -> + val res = cmp(a, b) + if (res == 0) return ComparisonResult.EQ + if (res < 0) return ComparisonResult.LS + return ComparisonResult.GR +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/util/IComparable.json b/test/datagen/kotlin/kotlin-compiler-tests/examples/util/IComparable.json new file mode 100644 index 000000000..bc9d80555 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/util/IComparable.json @@ -0,0 +1,51 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "IComparable", + "kind": "CLASS", + "modifiers": [ + { + "kind": "OTHER", + "other": "open" + } + ], + "generic_parameters": [ + { + "name": "in T", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "compareTo", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "other", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/examples/util/IComparable.kt b/test/datagen/kotlin/kotlin-compiler-tests/examples/util/IComparable.kt new file mode 100644 index 000000000..1ce3f600e --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/examples/util/IComparable.kt @@ -0,0 +1,3 @@ +open class IComparable { + fun compareTo(other : T) : Int +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionTypesWithFunctionReceivers.json b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionTypesWithFunctionReceivers.json new file mode 100644 index 000000000..04da527d9 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionTypesWithFunctionReceivers.json @@ -0,0 +1,99 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(((S).() -> S).() -> S)", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "((T.() -> S).() -> S)", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "((T.T.() -> S).() -> S)", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "((T.T.() -> S).() -> S)", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "(((S).() -> S).() -> S)", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "@[a] (@[a] ((S).() -> S).() -> S)", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "@[a] (@[a] (T.() -> S).() -> S)", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "@[a] (@[a] (T.() -> S).() -> S)", + "kind": "OTHER" + } + ] + }, + { + "name": "f", + "kind": "ALIAS", + "parents": [ + { + "name": "@[a] (@[a] ((S).() -> S).() -> S)", + "kind": "OTHER" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionTypesWithFunctionReceivers.kt b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionTypesWithFunctionReceivers.kt new file mode 100644 index 000000000..ebcdce203 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionTypesWithFunctionReceivers.kt @@ -0,0 +1,10 @@ +typealias f = (((S).() -> S).() -> S) +typealias f = ((T.() -> S).() -> S) +typealias f = ((T.T.() -> S).() -> S) +typealias f = ((T.T.() -> S).() -> S) +typealias f = (((S).() -> S).() -> S) + +typealias f = @[a] (@[a] ((S).() -> S).() -> S) +typealias f = @[a] (@[a] (T.() -> S).() -> S) +typealias f = @[a] (@[a] (T.() -> S).() -> S) +typealias f = @[a] (@[a] ((S).() -> S).() -> S) \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionsWithFunctionReceiversAnnotations.json b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionsWithFunctionReceiversAnnotations.json new file mode 100644 index 000000000..9defc5e92 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionsWithFunctionReceiversAnnotations.json @@ -0,0 +1,76 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "receiver_type": { + "name": "(@[a] T.(A) -> Unit)", + "kind": "OTHER" + } + }, + { + "name": "foo", + "receiver_type": { + "name": "(@[a] T.(A) -> C)", + "kind": "OTHER" + } + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK" + } + ], + "receiver_type": { + "name": "@[a] (@[a] T.(A) -> R)", + "kind": "OTHER" + } + }, + { + "name": "foo", + "generic_parameters": [ + { + "name": "A", + "kind": "GENERIC" + }, + { + "name": "B", + "kind": "GENERIC" + } + ], + "receiver_type": { + "name": "@[a] (() -> Unit)", + "kind": "OTHER" + } + }, + { + "name": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ], + "generic_parameters": [ + { + "name": "A", + "kind": "GENERIC" + }, + { + "name": "B", + "kind": "GENERIC" + } + ], + "receiver_type": { + "name": "@[a] ((A, B) -> Unit)", + "kind": "OTHER" + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionsWithFunctionReceiversAnnotations.kt b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionsWithFunctionReceiversAnnotations.kt new file mode 100644 index 000000000..9b8f8e33b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/FunctionsWithFunctionReceiversAnnotations.kt @@ -0,0 +1,5 @@ +fun (@[a] T.(A) -> Unit).foo() +fun (@[a] T.(A) -> C).foo(); +fun @[a] (@[a] T.(A) -> R).foo() {} +fun @[a] (() -> Unit).foo() +@[a] fun @[a] ((A, B) -> Unit).foo() diff --git a/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/PropertiesWithFunctionReceiversAnnotations.json b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/PropertiesWithFunctionReceiversAnnotations.json new file mode 100644 index 000000000..e69de29bb diff --git a/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/PropertiesWithFunctionReceiversAnnotations.kt b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/PropertiesWithFunctionReceiversAnnotations.kt new file mode 100644 index 000000000..cefe1308e --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/functionReceivers/PropertiesWithFunctionReceiversAnnotations.kt @@ -0,0 +1,5 @@ +val (@[a] T.(A) -> Unit).foo: P +val (@[a] T.(A) -> C).foo: P +val @[a] (@[a] T.(A) -> R).foo: P +val @[a] (() -> Unit).foo: P +@[a] val @[a] ((A, B) -> Unit).foo: P diff --git a/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/FunctionTypesAsArguments.json b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/FunctionTypesAsArguments.json new file mode 100644 index 000000000..01969fde3 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/FunctionTypesAsArguments.json @@ -0,0 +1,70 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Lifetime", + "kind": "CLASS", + "fields": [ + { + "name": "attached", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "()->Unit", + "kind": "GENERIC" + } + ], + "method": "ArrayList" + } + } + ] + } + ], + "variables": [ + { + "name": "commands", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "java" + } + ], + "variable": "util" + } + ], + "generic_parameters": [ + { + "name": "String", + "kind": "GENERIC" + }, + { + "name": "() -> Unit", + "kind": "GENERIC" + } + ], + "method": "HashMap" + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/FunctionTypesAsArguments.kt b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/FunctionTypesAsArguments.kt new file mode 100644 index 000000000..7611cfa0f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/FunctionTypesAsArguments.kt @@ -0,0 +1,5 @@ +val commands = java.util.HashMap Unit>() // multiple errors + +class Lifetime{ + val attached = ArrayList<()->Unit>() +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/functionLiterals.json b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/functionLiterals.json new file mode 100644 index 000000000..0577e5e55 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/functionLiterals.json @@ -0,0 +1,288 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "CLASS" + }, + { + "name": "Bar", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "a", + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "vararg" + } + ] + } + ], + "expression": { + "kind": "VARACCESS", + "variable": "a" + } + }, + { + "name": "test", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "a", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/functionLiterals.kt b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/functionLiterals.kt new file mode 100644 index 000000000..1c5601d26 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/functionLiterals.kt @@ -0,0 +1,18 @@ +class Foo +class Bar + +fun a(vararg a : Any) = a + +fun test() { +a(1 +, {} +, { -> 1} +, {1} +, {x} +, {-> 1} +, {x -> 1} +, {x, y -> 1} +, {x -> 1} +, {(x)} +) +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/nullableTypes.json b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/nullableTypes.json new file mode 100644 index 000000000..f3f4c7ae8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/nullableTypes.json @@ -0,0 +1,268 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "test", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ELVIS", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "X", + "kind": "OTHER" + }, + "safe": true + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "RETURN" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ELVIS", + "expressions": [ + { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "new_type": { + "name": "X?", + "kind": "OTHER" + } + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "RETURN" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "X?" + } + ], + "method": "x" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "X?" + } + ], + "method": "x" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "X??" + } + ], + "method": "x" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "X??" + } + ], + "method": "x" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "X??" + } + ], + "method": "x" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "X?.() -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "X??.() -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "X?? .() -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "X ? .() -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "X ?.() -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/nullableTypes.kt b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/nullableTypes.kt new file mode 100644 index 000000000..e8af5174b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/greatSyntacticShift/nullableTypes.kt @@ -0,0 +1,16 @@ +fun test() { + x as? X ?: return + x as X? ?: return + + X?::x + X ?:: x + X? ?:: x + X ??:: x + X ?? :: x + + val x: X?.() -> Unit + val x: X??.() -> Unit + val x: X?? .() -> Unit + val x: X ? .() -> Unit + val x: X ?.() -> Unit +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/newLabels/basic.json b/test/datagen/kotlin/kotlin-compiler-tests/newLabels/basic.json new file mode 100644 index 000000000..a530b32fb --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/newLabels/basic.json @@ -0,0 +1,385 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x1" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "b" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "c" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "loop1" + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "4" + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "100" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "loop2" + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "loop2" + }, + { + "kind": "LITERAL", + "literal": "4" + }, + { + "kind": "LABEL", + "literal": "loop2" + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "loop2" + }, + { + "kind": "LITERAL", + "literal": "5" + }, + { + "kind": "LABEL", + "literal": "loop2" + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "100" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "label1" + }, + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "1" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "label3" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ] + }, + { + "kind": "LITERAL", + "literal": "4" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OTHER", + "expressions": [ + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "l1" + }, + { + "kind": "VARACCESS", + "variable": "foo" + } + ] + } + ] + }, + { + "kind": "STATEMENT", + "statements": [ + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "l2" + }, + { + "kind": "VARACCESS", + "variable": "baz" + } + ] + } + ] + } + ], + "literal": "bar" + } + ] + }, + { + "kind": "LABEL", + "expressions": [ + { + "kind": "LABEL", + "literal": "a" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "PAREN" + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/newLabels/basic.kt b/test/datagen/kotlin/kotlin-compiler-tests/newLabels/basic.kt new file mode 100644 index 000000000..7b8c765c4 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/newLabels/basic.kt @@ -0,0 +1,25 @@ +fun foo() { + x1.filter b@ { + return 1 + } + c@ { + return 2 + } + + loop1@ for (i in 1..100) { + return 4 + } + + loop2@ for (i in 1..100) { + return@loop2 4 + return@loop2 5 + } + + label1@ val x = 1 + + 1 + label3@ 3 + 4 + + l1@ foo bar l2@ baz // binary expression + + return (a@ 1) +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/newLabels/oldSyntaxExpressions.json b/test/datagen/kotlin/kotlin-compiler-tests/newLabels/oldSyntaxExpressions.json new file mode 100644 index 000000000..bd9a1b152 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/newLabels/oldSyntaxExpressions.json @@ -0,0 +1,156 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "STATEMENT", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "loop1" + } + ], + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK" + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "100" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x2" + } + ], + "method": "filter", + "method_args": [ + { + "kind": "LAMBDA", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "f" + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "f" + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "1" + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/newLabels/oldSyntaxExpressions.kt b/test/datagen/kotlin/kotlin-compiler-tests/newLabels/oldSyntaxExpressions.kt new file mode 100644 index 000000000..81ffaaa8e --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/newLabels/oldSyntaxExpressions.kt @@ -0,0 +1,11 @@ +fun foo() { + @loop1 for (i in 1..100) { } + + x2.filter @f { + return 2 + } + + return (@f 3) + + val x = 1 +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/packages/PackageModifiers.json b/test/datagen/kotlin/kotlin-compiler-tests/packages/PackageModifiers.json new file mode 100644 index 000000000..0af0e4b4a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/packages/PackageModifiers.json @@ -0,0 +1,17 @@ +{ + "namespaces": [ + { + "name": "name", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + }, + { + "kind": "ANNOTATION", + "annotation_name": "a" + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/packages/PackageModifiers.kt b/test/datagen/kotlin/kotlin-compiler-tests/packages/PackageModifiers.kt new file mode 100644 index 000000000..fe991547c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/packages/PackageModifiers.kt @@ -0,0 +1 @@ +public @[a] package name \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/FunctionsNotPlatform.json b/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/FunctionsNotPlatform.json new file mode 100644 index 000000000..9c2b41047 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/FunctionsNotPlatform.json @@ -0,0 +1,110 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "arguments": [ + { + "name": "f", + "variable_type": { + "name": "(Mutable) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "f", + "variable_type": { + "name": "T.(Mutable) -> Unit", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "f", + "variable_type": { + "name": "Array<(out) -> Unit>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "f", + "variable_type": { + "name": "Array Unit>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/FunctionsNotPlatform.kt b/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/FunctionsNotPlatform.kt new file mode 100644 index 000000000..01541686c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/FunctionsNotPlatform.kt @@ -0,0 +1,4 @@ +fun foo(f: (Mutable) -> Unit) {} +fun foo(f: T.(Mutable) -> Unit) {} +fun foo(f: Array<(out) -> Unit>) {} +fun foo(f: Array Unit>) {} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/ParenthesizedNotPlatform.json b/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/ParenthesizedNotPlatform.json new file mode 100644 index 000000000..51a2d4050 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/ParenthesizedNotPlatform.json @@ -0,0 +1,59 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "arguments": [ + { + "name": "f", + "variable_type": { + "name": "(Mutable)", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "f", + "variable_type": { + "name": "Array<(out)>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/ParenthesizedNotPlatform.kt b/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/ParenthesizedNotPlatform.kt new file mode 100644 index 000000000..3090af730 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/platformTypesRecovery/ParenthesizedNotPlatform.kt @@ -0,0 +1,2 @@ +fun foo(f: (Mutable)) {} +fun foo(f: Array<(out)>) {} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/primaryConstructor/valid.json b/test/datagen/kotlin/kotlin-compiler-tests/primaryConstructor/valid.json new file mode 100644 index 000000000..b97f717a5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/primaryConstructor/valid.json @@ -0,0 +1,274 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A0", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ] + } + ] + }, + { + "name": "A1", + "kind": "CLASS", + "parents": [ + { + "name": "Base1", + "kind": "CLASS" + }, + { + "name": "Base2", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "Base1" + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "A2", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "ANNOTATION", + "annotation_name": "private" + } + ], + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "A3", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "A4", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann", + "annotation_values": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ], + "arguments": [ + { + "name": "y", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "A5", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + } + ] + }, + { + "name": "A6", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "ANNOTATION", + "annotation_name": "Ann" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/primaryConstructor/valid.kt b/test/datagen/kotlin/kotlin-compiler-tests/primaryConstructor/valid.kt new file mode 100644 index 000000000..779ee5748 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/primaryConstructor/valid.kt @@ -0,0 +1,15 @@ +class A0 +constructor() {} +class A1 +private constructor(y: Int) : Base1(), Base2 { + val x: Int +} +class A2 @private constructor(y: Int) + +class A3 @Ann(1) private constructor(y: Int) + +class A4 private @Ann(1) constructor(y: Int) + +class A5 @Ann private constructor() {} + +class A6 @Ann() private constructor() {} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/BracketsInDelegate.json b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/BracketsInDelegate.json new file mode 100644 index 000000000..9ebe593fd --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/BracketsInDelegate.json @@ -0,0 +1,35 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "a", + "variable_type": { + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "A", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/BracketsInDelegate.kt b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/BracketsInDelegate.kt new file mode 100644 index 000000000..7e3a3b707 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/BracketsInDelegate.kt @@ -0,0 +1 @@ +val a by A {} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/GetterInSameLine.json b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/GetterInSameLine.json new file mode 100644 index 000000000..251981ad8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/GetterInSameLine.json @@ -0,0 +1,34 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "a.", + "expression": { + "kind": "LITERAL", + "literal": "1" + } + } + ], + "variables": [ + { + "name": "a", + "variable_type": { + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "A" + } + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/GetterInSameLine.kt b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/GetterInSameLine.kt new file mode 100644 index 000000000..470264649 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/GetterInSameLine.kt @@ -0,0 +1 @@ +val a by A(); get() = 1; \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/LocalProperty.json b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/LocalProperty.json new file mode 100644 index 000000000..68dfe128d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/LocalProperty.json @@ -0,0 +1,51 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "B", + "kind": "CLASS", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "p", + "variable_type": { + "name": "Int", + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "A" + } + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/LocalProperty.kt b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/LocalProperty.kt new file mode 100644 index 000000000..d549eae7d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/LocalProperty.kt @@ -0,0 +1,5 @@ +class B { + fun foo() { + val p: Int by A() + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyInClass.json b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyInClass.json new file mode 100644 index 000000000..c3e8e739e --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyInClass.json @@ -0,0 +1,31 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "B", + "kind": "CLASS", + "fields": [ + { + "name": "p", + "variable_type": { + "name": "Int", + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "A" + } + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyInClass.kt b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyInClass.kt new file mode 100644 index 000000000..db6cdb61f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyInClass.kt @@ -0,0 +1,3 @@ +class B { + val p: Int by A() +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithGetter.json b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithGetter.json new file mode 100644 index 000000000..f36bad81a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithGetter.json @@ -0,0 +1,38 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "p.", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "LITERAL", + "literal": "1" + } + } + ], + "variables": [ + { + "name": "p", + "variable_type": { + "name": "Int", + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "A" + } + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithGetter.kt b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithGetter.kt new file mode 100644 index 000000000..7a6902ef7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithGetter.kt @@ -0,0 +1,2 @@ +val p: Int by A() + get() = 1 \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithInitializer.json b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithInitializer.json new file mode 100644 index 000000000..54a47d71f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithInitializer.json @@ -0,0 +1,34 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "p", + "variable_type": { + "name": "Int", + "kind": "DELEGATED", + "delegate": { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "METHODCALL", + "method": "A" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithInitializer.kt b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithInitializer.kt new file mode 100644 index 000000000..9a82d77bc --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithInitializer.kt @@ -0,0 +1 @@ +val p: Int by A() = 1 \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithoutTypeRef.json b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithoutTypeRef.json new file mode 100644 index 000000000..e6c1caf2e --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithoutTypeRef.json @@ -0,0 +1,25 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "p", + "variable_type": { + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "A" + } + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithoutTypeRef.kt b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithoutTypeRef.kt new file mode 100644 index 000000000..03da513a8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/PropertyWithoutTypeRef.kt @@ -0,0 +1 @@ +val p by A() \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TopLevelProperty.json b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TopLevelProperty.json new file mode 100644 index 000000000..6974593be --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TopLevelProperty.json @@ -0,0 +1,25 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "p", + "variable_type": { + "name": "Int", + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "A" + } + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TopLevelProperty.kt b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TopLevelProperty.kt new file mode 100644 index 000000000..6fd11d86c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TopLevelProperty.kt @@ -0,0 +1 @@ +val p: Int by A() \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TwoProperties.json b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TwoProperties.json new file mode 100644 index 000000000..0f36b524c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TwoProperties.json @@ -0,0 +1,40 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "a", + "variable_type": { + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "A" + } + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "kind": "DELEGATED", + "delegate": { + "kind": "METHODCALL", + "method": "A" + } + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TwoProperties.kt b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TwoProperties.kt new file mode 100644 index 000000000..95a3745c4 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/propertyDelegate/TwoProperties.kt @@ -0,0 +1 @@ +val a by A(); val b by A(); diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/InterfaceInExpressionPosition.json b/test/datagen/kotlin/kotlin-compiler-tests/recovery/InterfaceInExpressionPosition.json new file mode 100644 index 000000000..4c8406dea --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/InterfaceInExpressionPosition.json @@ -0,0 +1,44 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "p", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "OTHER", + "anon_declaration": { + "name": "I", + "kind": "INTERFACE", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + } + ] + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/InterfaceInExpressionPosition.kt b/test/datagen/kotlin/kotlin-compiler-tests/recovery/InterfaceInExpressionPosition.kt new file mode 100644 index 000000000..b23b2a59b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/InterfaceInExpressionPosition.kt @@ -0,0 +1,3 @@ +val p = 1 < interface I { + fun f() {} +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ConstructorModifiers.json b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ConstructorModifiers.json new file mode 100644 index 000000000..5a1a1d869 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ConstructorModifiers.json @@ -0,0 +1,100 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "SINGLETON", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "parents": [ + { + "name": "Bar", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "ANNOTATION", + "annotation_name": "foo" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "ANNOTATION", + "annotation_name": "bar" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ConstructorModifiers.kt b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ConstructorModifiers.kt new file mode 100644 index 000000000..6217446f6 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ConstructorModifiers.kt @@ -0,0 +1,9 @@ +object Foo private () + +object Foo private () {} + +object Foo private () : Bar { + +} + +object Foo @[foo] private @[bar()] () \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/EmptyParentheses.json b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/EmptyParentheses.json new file mode 100644 index 000000000..c33ad9d37 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/EmptyParentheses.json @@ -0,0 +1,60 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "SINGLETON", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ] + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ] + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "parents": [ + { + "name": "Bar", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/EmptyParentheses.kt b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/EmptyParentheses.kt new file mode 100644 index 000000000..bfee8b8bb --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/EmptyParentheses.kt @@ -0,0 +1,7 @@ +object Foo() + +object Foo() {} + +object Foo() : Bar { + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/Everything.json b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/Everything.json new file mode 100644 index 000000000..8918a0edf --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/Everything.json @@ -0,0 +1,88 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "SINGLETON", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + }, + { + "name": "R", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "Bar", + "kind": "CLASS" + }, + { + "name": "Baz", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + }, + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/Everything.kt b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/Everything.kt new file mode 100644 index 000000000..210cc26d2 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/Everything.kt @@ -0,0 +1,3 @@ +object Foo private (x: Int, y: Int) : Bar, Baz { + fun foo() {} +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/FollowedByModifiers.json b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/FollowedByModifiers.json new file mode 100644 index 000000000..eb513eb7b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/FollowedByModifiers.json @@ -0,0 +1,37 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "SINGLETON" + }, + { + "name": "Bar", + "kind": "CLASS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON" + }, + { + "name": "Bar", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "foo" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/FollowedByModifiers.kt b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/FollowedByModifiers.kt new file mode 100644 index 000000000..ef5eda15a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/FollowedByModifiers.kt @@ -0,0 +1,7 @@ +object Foo + +public class Bar + +object Foo + +@[foo] class Bar \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ParametersInParentheses.json b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ParametersInParentheses.json new file mode 100644 index 000000000..83a49817a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ParametersInParentheses.json @@ -0,0 +1,156 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "SINGLETON", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "parents": [ + { + "name": "Bar", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "a", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "b", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ParametersInParentheses.kt b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ParametersInParentheses.kt new file mode 100644 index 000000000..7cd5f327e --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/ParametersInParentheses.kt @@ -0,0 +1,7 @@ +object Foo(a: Int, b: String) + +object Foo(a: Int, b: String) {} + +object Foo(a: Int, b: String) : Bar { + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParametersAndParentheses.json b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParametersAndParentheses.json new file mode 100644 index 000000000..6dad8e98d --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParametersAndParentheses.json @@ -0,0 +1,108 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "SINGLETON", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + }, + { + "name": "R", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ] + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + }, + { + "name": "R", + "kind": "GENERIC" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + }, + { + "name": "R", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "Bar", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParametersAndParentheses.kt b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParametersAndParentheses.kt new file mode 100644 index 000000000..a2fa186a7 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParametersAndParentheses.kt @@ -0,0 +1,7 @@ +object Foo() + +object Foo(x: Int) {} + +object Foo() : Bar { + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParameterss.json b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParameterss.json new file mode 100644 index 000000000..b3fba1c03 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParameterss.json @@ -0,0 +1,57 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "SINGLETON", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + }, + { + "name": "R", + "kind": "GENERIC" + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + }, + { + "name": "R", + "kind": "GENERIC" + } + ] + }, + { + "name": "Foo", + "kind": "SINGLETON", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + }, + { + "name": "R", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "Bar", + "kind": "CLASS" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParameterss.kt b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParameterss.kt new file mode 100644 index 000000000..7ed3af0ad --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/recovery/objects/declarations/TypeParameterss.kt @@ -0,0 +1,7 @@ +object Foo + +object Foo {} + +object Foo : Bar { + +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/ComplexScript.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/ComplexScript.kts new file mode 100644 index 000000000..2f084378c --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/ComplexScript.kts @@ -0,0 +1,12 @@ +fun die(message: String) { + System.err.println(message) + System.exit(1) +} + +if (args.length == 0) { + die("Need arguments") +} + +for (arg in args) { + println(arg) +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/Import.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/Import.kts new file mode 100644 index 000000000..a4a39f01e --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/Import.kts @@ -0,0 +1,4 @@ +import aaa.bbb.Ccc +import ddd.* + +fun foo() = 1 diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/OneLiner.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/OneLiner.kts new file mode 100644 index 000000000..85bcd04e9 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/OneLiner.kts @@ -0,0 +1 @@ +val x = 6; println(x * 7) diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/Shebang.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/Shebang.kts new file mode 100644 index 000000000..9d085c7eb --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/Shebang.kts @@ -0,0 +1,3 @@ +#!/usr/bin/env kotlin + +println(args) diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/ShebangIncorrect.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/ShebangIncorrect.kts new file mode 100644 index 000000000..b2db2bab5 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/ShebangIncorrect.kts @@ -0,0 +1,3 @@ +println(1); #!/usr + +#!/hi diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/ShebangWithImports.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/ShebangWithImports.kts new file mode 100644 index 000000000..16f227f2f --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/ShebangWithImports.kts @@ -0,0 +1,5 @@ +#!/usr/bin/env kotlin + +import test + +println(args) diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/ShebangWithPackage.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/ShebangWithPackage.kts new file mode 100644 index 000000000..5e99ff12b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/ShebangWithPackage.kts @@ -0,0 +1,5 @@ +#!/usr/bin/env kotlin + +package test + +println(args) diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/SimpleScript.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/SimpleScript.kts new file mode 100644 index 000000000..458f620a8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/SimpleScript.kts @@ -0,0 +1 @@ +println(1) diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/manyAnnotationsOnFile.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/manyAnnotationsOnFile.kts new file mode 100644 index 000000000..62feb7a88 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/manyAnnotationsOnFile.kts @@ -0,0 +1,3 @@ +@file:[ foo] +@file:[bar baz] +package bar diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/topLevelPropertiesWithGetSet.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/topLevelPropertiesWithGetSet.kts new file mode 100644 index 000000000..236f903d2 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/topLevelPropertiesWithGetSet.kts @@ -0,0 +1,54 @@ +val testVal: Int get() = 42 + +val testValSemiSameLine: Int; get() = 42 + +val testValNoType get() = 42 + +val String.testExtVal: Int get() = 42 + +val String.testExtValNoType get() = 42 + +var testVar: Int get() = 42; set(value) {} + +var String.testExtVar: Int get() = 42; set(value) {} + +val testValLineBreak: Int + get() = 42 + +val testValLineBreakNoType + get() = 42 + +val testValLineBreakSemi: Int; + get() = 42 + +val testValLineBreakSemiComment1: Int; // this IS NOT an accessor: + get() = 42 + +val testValLineBreakSemiComment2: Int; /* +this IS NOT an accessor either: +*/ + get() = 42 + +val testValLineBreakSemiComment3: Int; /* +this IS an accessor! +*/ get() = 42 + +val testValLineBreakSemiNoType; + get() = 42 + +var testVarLineBreak: Int + get() = 42 + set(value) {} + +var String.testExtVarLineBreak: Int + get() = 42 + set(value) {} + +var testVarLineBreakSemi: Int; + get() = 42 + set(value) {} + +var String.testExtVarLineBreakSemi: Int; + get() = 42 + set(value) {} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/script/unexpectedSymbol.kts b/test/datagen/kotlin/kotlin-compiler-tests/script/unexpectedSymbol.kts new file mode 100644 index 000000000..5b52dacaa --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/script/unexpectedSymbol.kts @@ -0,0 +1,2 @@ +println(1) +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/anonymousInitializer.json b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/anonymousInitializer.json new file mode 100644 index 000000000..bb0cca58b --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/anonymousInitializer.json @@ -0,0 +1,79 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "methods": [ + { + "name": "", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "f" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/anonymousInitializer.kt b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/anonymousInitializer.kt new file mode 100644 index 000000000..d37452470 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/anonymousInitializer.kt @@ -0,0 +1,10 @@ +class A { + init {} + + private init {} + + val x = f() + init { + x = 1 + } +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/basic.json b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/basic.json new file mode 100644 index 000000000..1ce3d7de1 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/basic.json @@ -0,0 +1,212 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "methods": [ + { + "name": "", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "ANNOTATION", + "annotation_name": "annot" + } + ], + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "constructor", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "constructor" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "annot" + }, + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + } + ], + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ], + "method": "this" + } + ] + }, + { + "kind": "BLOCK" + } + ] + }, + { + "name": "", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "constructor" + }, + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + } + ], + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "super" + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "ASSIGN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "B", + "kind": "CLASS", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "constructor" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/basic.kt b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/basic.kt new file mode 100644 index 000000000..02402a62e --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/basic.kt @@ -0,0 +1,17 @@ +class A { + constructor() {} + + val x: Int + + private @annot constructor(x: Int) {} + + @constructor fun constructor() {} + + @annot protected constructor(x: Int, y: Int) : this(1,2) {} + + @[constructor] public constructor() : super() { + x = 1 + } +} + +@constructor class B diff --git a/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/emptyBody.json b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/emptyBody.json new file mode 100644 index 000000000..13f275ee9 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/emptyBody.json @@ -0,0 +1,95 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "methods": [ + { + "name": "" + }, + { + "name": "foo", + "expression": { + "kind": "LITERAL", + "literal": "1" + } + }, + { + "name": "", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + } + ] + }, + { + "name": "", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "this" + } + ] + } + ] + }, + { + "name": "", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + } + ], + "method": "super" + } + ] + } + ] + } + ], + "fields": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "2" + } + }, + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "4" + } + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/emptyBody.kt b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/emptyBody.kt new file mode 100644 index 000000000..404345d03 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/emptyBody.kt @@ -0,0 +1,10 @@ +class A { + constructor() + fun foo() = 1 + public constructor() + val x = 2 + + constructor(): this() + constructor(): super(3) + val x = 4 +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/enumParsing.json b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/enumParsing.json new file mode 100644 index 000000000..2baff6723 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/enumParsing.json @@ -0,0 +1,199 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "ENUM", + "modifiers": [ + { + "kind": "OTHER", + "other": "enum" + } + ], + "methods": [ + { + "name": "", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "", + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "this" + } + ] + }, + { + "kind": "BLOCK" + } + ] + }, + { + "name": "", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "fields": [ + { + "name": "abc1", + "variable_type": { + "name": "A", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ], + "new_type": { + "name": "A", + "kind": "ENUM" + } + } + ] + }, + { + "name": "abc2", + "variable_type": { + "name": "A", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ], + "initializer": { + "kind": "NEW", + "anon_declaration": { + "name": "A", + "kind": "ENUM" + } + }, + "expressions": [ + { + "kind": "NEW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ], + "new_type": { + "name": "A", + "kind": "ENUM" + } + } + ] + }, + { + "name": "abc3", + "variable_type": { + "name": "A", + "kind": "ENUM" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/enumParsing.kt b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/enumParsing.kt new file mode 100644 index 000000000..200a353d8 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/secondaryConstructors/enumParsing.kt @@ -0,0 +1,14 @@ +enum class A { + abc1(1,2,3), + abc2(1,2,3) {}, + abc3; + + constructor(x: Int) {} + + init {} + + constructor(x: Int): this() {} + init { + + } +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/stringTemplates/RawStringsWithManyQuotes.json b/test/datagen/kotlin/kotlin-compiler-tests/stringTemplates/RawStringsWithManyQuotes.json new file mode 100644 index 000000000..32fb0d6d0 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/stringTemplates/RawStringsWithManyQuotes.json @@ -0,0 +1,145 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\"\"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\"\"\"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\"\"\"\"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\"\"\"\"\"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\"\" \"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\"\"\" \"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\" \"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\" \"\"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\" \"\"\"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\" \"\"\"\"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\" \"\"\"\"\"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\"\" \"\"\"\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"\"\"\"\" \"\"\"\"\"" + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/stringTemplates/RawStringsWithManyQuotes.kt b/test/datagen/kotlin/kotlin-compiler-tests/stringTemplates/RawStringsWithManyQuotes.kt new file mode 100644 index 000000000..d302e5a38 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/stringTemplates/RawStringsWithManyQuotes.kt @@ -0,0 +1,19 @@ +fun foo() { + """""" + """"""" + """""""" + """"""""" + """""""""" + + """" """ + """"" """ + + """ """" + """ """"" + """ """""" + """ """"""" + """ """""""" + + """" """" + """"" """"" +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/trailingCommaAllowed.json b/test/datagen/kotlin/kotlin-compiler-tests/trailingCommaAllowed.json new file mode 100644 index 000000000..0da990354 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/trailingCommaAllowed.json @@ -0,0 +1,1421 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "A", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Comparable>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "Iterable>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "x.", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "x.", + "return_type": { + "name": "Unit", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "value", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "x.", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "x.", + "return_type": { + "name": "Unit", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "value", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "x.", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "LITERAL", + "literal": "10" + } + }, + { + "name": "x.", + "return_type": { + "name": "Unit", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "value", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ], + "fields": [ + { + "name": "x", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + } + }, + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + } + }, + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + } + } + ] + }, + { + "name": "A", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "T1 : Number", + "kind": "GENERIC" + }, + { + "name": "T2 : Iterable>>", + "kind": "GENERIC" + }, + { + "name": "T3 : Comparable>>", + "kind": "GENERIC" + } + ] + } + ], + "methods": [ + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "Number", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "foo", + "expression": { + "kind": "METHODCALL", + "method": "listOf", + "method_args": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo" + } + ], + "variable": "bar" + } + ], + "method": "something" + }, + { + "kind": "LITERAL", + "literal": "\"foo bar something\"" + } + ] + } + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "ARRAYACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "main", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "Comparable>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "Iterable>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"1\"" + } + ] + } + ] + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "Comparable>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "Iterable>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"1\"" + } + ] + } + ] + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "z", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "Comparable>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "Iterable>", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"1\"" + } + ] + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Comparable" + } + ], + "method": "Comparable::class" + }, + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Iterable" + } + ], + "method": "Iterable::class" + }, + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "String" + } + ], + "method": "String::class" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "DEFAULT" + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Comparable" + } + ], + "method": "Comparable::class" + }, + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Iterable" + } + ], + "method": "Iterable::class" + }, + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "String" + } + ], + "method": "String::class" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "DEFAULT" + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + }, + { + "name": "foo", + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Any", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "expression": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Comparable" + } + ], + "method": "Comparable::class" + }, + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "Iterable" + } + ], + "method": "Iterable::class" + }, + { + "kind": "METHOD_REFERENCE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "String" + } + ], + "method": "String::class" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + }, + { + "kind": "DEFAULT" + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + }, + { + "name": "foo", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Anno", + "annotation_values": [ + { + "kind": "ARRAYINIT", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + }, + { + "kind": "LITERAL", + "literal": "3" + }, + { + "kind": "LITERAL", + "literal": "4" + } + ] + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "main", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "Pair", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "Pair", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "generic_parameters": [ + { + "name": "T1 : Comparable>", + "kind": "GENERIC" + }, + { + "name": "T2 : Iterable>", + "kind": "GENERIC" + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + }, + { + "name": "main", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "Comparable>", + "kind": "GENERIC" + }, + { + "name": "Iterable>", + "kind": "GENERIC" + } + ], + "method": "foo" + } + ] + } + ] + } + ] + }, + { + "name": "main", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "variable_type": { + "name": "(\n y: Comparable>,\n z: Iterable>,\n ) -> Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "10" + } + ] + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "foo", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "TRY", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "CATCH", + "variable_declarations": [ + { + "name": "e", + "variable_type": { + "name": "Exception", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "foo", + "variable_type": { + "name": "(Int, Int) -> Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + } + ] + } + ] + } + ] + } + }, + { + "name": "foo", + "variable_type": { + "name": "(Int, Int, Int) -> Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODDECL", + "methods": [ + { + "name": "", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "x", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "z", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "RETURN", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + } + ] + } + ] + } + ] + } + }, + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "z", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ] + }, + { + "name": "z", + "modifiers": [ + { + "kind": "FINAL" + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/kotlin-compiler-tests/trailingCommaAllowed.kt b/test/datagen/kotlin/kotlin-compiler-tests/trailingCommaAllowed.kt new file mode 100644 index 000000000..51f043b66 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/trailingCommaAllowed.kt @@ -0,0 +1,157 @@ +class A( + val x: String, + val y: String, +) { + constructor( + x: Comparable>, + y: Iterable> , + ) {} + + var x: Int + get() = 10 + set(value,) { + + } + + var x: Int + get() = 10 + set(value,/*...*/) { + + } + + var x: Int + get() = 10 + set(value/*...*/,) { + + } +} + +fun foo( + x: Int, + y: Number + , +) {} + +val foo: (Int, Int) -> Int = fun(x, + y, ): Int { + return x + y +} + +val foo: (Int, Int, Int) -> Int = + fun (x, + y: Int, z, + ): Int { + return x + y + } + +fun foo() = listOf( + foo.bar.something(), + "foo bar something" + , + ) + +fun foo() { + val x = x[ + 1, + 3 + , ] + val y = x[ + 1, + 3 + , + ] +} + +fun main() { + val x = { + x: Comparable>, + y: Iterable> + ,-> + println("1") + } + val y = { + x: Comparable>, + y: Iterable>, + -> println("1") + } + val z = { + x: Comparable>, + y: Iterable> + , + -> + println("1") + } +} + +fun foo(x: Any) = when (x) { + Comparable::class, + Iterable::class, + String::class, + -> println(1) + else -> println(3) +} + +fun foo(x: Any) = when (x) { + Comparable::class, + Iterable::class, + String::class,-> + println(1) + else -> println(3) +} + +fun foo(x: Any) = when (x) { + Comparable::class, + Iterable::class, + String::class + , + -> + println(1) + else -> println(3) +} + +@Anno([1, 2, 3, 4 + ,] +) +fun foo() {} + +fun main() { + val ( + y, + z, + ) = Pair(1, 2) + val ( + y, + z + , ) = Pair(1, 2) +} + +class A< + T1: Number, + T2: Iterable>>, + T3: Comparable>>, + > { } + +fun < + T1: Comparable>, + T2: Iterable> + , + > foo() {} + +fun main() { + foo>, Iterable>,>() +} + +fun main() { + val x: ( + y: Comparable>, + z: Iterable>, + ) -> Int = { 10 } + + val y = foo(1,) {} + + try { + println(1) + } catch (e: Exception,) { + + } +} diff --git a/test/datagen/kotlin/kotlin-compiler-tests/validKotlinFunInterface.json b/test/datagen/kotlin/kotlin-compiler-tests/validKotlinFunInterface.json new file mode 100644 index 000000000..e3f18fb7a --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/validKotlinFunInterface.json @@ -0,0 +1,88 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Foo", + "kind": "INTERFACE", + "modifiers": [ + { + "kind": "OTHER", + "other": "fun" + } + ] + }, + { + "name": "Foo", + "kind": "INTERFACE", + "modifiers": [ + { + "kind": "OTHER", + "other": "fun" + } + ], + "methods": [ + { + "name": "invoke" + } + ] + }, + { + "name": "Foo", + "kind": "INTERFACE", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + }, + { + "kind": "OTHER", + "other": "fun" + } + ] + }, + { + "name": "Foo", + "kind": "INTERFACE", + "modifiers": [ + { + "kind": "ANNOTATION", + "annotation_name": "Bar" + }, + { + "kind": "OTHER", + "other": "fun" + } + ] + }, + { + "name": "TopLevel", + "kind": "CLASS", + "nested_declarations": [ + { + "name": "Foo", + "kind": "INTERFACE", + "modifiers": [ + { + "kind": "OTHER", + "other": "fun" + } + ] + } + ] + }, + { + "name": "Foo", + "kind": "INTERFACE", + "modifiers": [ + { + "kind": "OTHER", + "other": "fun" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/kotlin-compiler-tests/validKotlinFunInterface.kt b/test/datagen/kotlin/kotlin-compiler-tests/validKotlinFunInterface.kt new file mode 100644 index 000000000..51d463625 --- /dev/null +++ b/test/datagen/kotlin/kotlin-compiler-tests/validKotlinFunInterface.kt @@ -0,0 +1,17 @@ +fun interface Foo + +fun interface Foo { + fun invoke() +} + +private fun interface Foo + +@Bar +fun interface Foo + +class TopLevel { + fun interface Foo +} + +fun +interface Foo \ No newline at end of file diff --git a/test/datagen/kotlin/lambda.json b/test/datagen/kotlin/lambda.json new file mode 100644 index 000000000..c69b5ecdf --- /dev/null +++ b/test/datagen/kotlin/lambda.json @@ -0,0 +1,242 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "items", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "listOf", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + }, + { + "kind": "LITERAL", + "literal": "3" + }, + { + "kind": "LITERAL", + "literal": "4" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "items" + } + ], + "method": "fold", + "method_args": [ + { + "kind": "LITERAL", + "literal": "0" + }, + { + "kind": "LAMBDA", + "variable_decls": [ + { + "name": "acc", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + }, + { + "name": "i", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "acc" + }, + { + "kind": "VARACCESS", + "variable": "i" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"hi\"" + } + ] + } + ] + } + ] + } + ] + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "x" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "items" + } + ], + "method": "forEach", + "method_args": [ + { + "kind": "LAMBDA", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_MOD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "it" + }, + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/lambda.kt b/test/datagen/kotlin/lambda.kt new file mode 100644 index 000000000..748fe2181 --- /dev/null +++ b/test/datagen/kotlin/lambda.kt @@ -0,0 +1,12 @@ +fun f() { + val items = listOf(1, 2, 3, 4, 5) + + items.fold(0, { + acc: Int, i: Int -> acc + i + }) + + val x = { print("hi") } + x() + + items.forEach { it % 2 } +} diff --git a/test/datagen/kotlin/method_definition.json b/test/datagen/kotlin/method_definition.json new file mode 100644 index 000000000..a0f04775e --- /dev/null +++ b/test/datagen/kotlin/method_definition.json @@ -0,0 +1,86 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "Six", + "kind": "CLASS", + "methods": [ + { + "name": "main", + "arguments": [ + { + "name": "args", + "variable_type": { + "name": "Array", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "args" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "bar", + "return_type": { + "name": "Quux", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "args", + "variable_type": { + "name": "Array", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK" + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/method_definition.kt b/test/datagen/kotlin/method_definition.kt new file mode 100644 index 000000000..2202a2eab --- /dev/null +++ b/test/datagen/kotlin/method_definition.kt @@ -0,0 +1,11 @@ +package boa.kotlin.test + +class Six { + fun main(args: Array) { + println(args) + } + + fun bar(args: Array): Quux { + + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/nested-klass.json b/test/datagen/kotlin/nested-klass.json new file mode 100644 index 000000000..3759a2775 --- /dev/null +++ b/test/datagen/kotlin/nested-klass.json @@ -0,0 +1,19 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "nested_declarations": [ + { + "name": "D", + "kind": "CLASS" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/nested-klass.kt b/test/datagen/kotlin/nested-klass.kt new file mode 100644 index 000000000..27c583254 --- /dev/null +++ b/test/datagen/kotlin/nested-klass.kt @@ -0,0 +1,4 @@ +class C { + class D { + } +} diff --git a/test/datagen/kotlin/noprimary-init.json b/test/datagen/kotlin/noprimary-init.json new file mode 100644 index 000000000..fee29d56b --- /dev/null +++ b/test/datagen/kotlin/noprimary-init.json @@ -0,0 +1,98 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Constructors", + "kind": "CLASS", + "methods": [ + { + "name": "", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"Init block\"" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "", + "arguments": [ + { + "name": "i", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"Constructor \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "i" + } + ], + "literal": "\"$i\"" + } + ], + "literal": "\"Constructor $i\"" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/noprimary-init.kt b/test/datagen/kotlin/noprimary-init.kt new file mode 100644 index 000000000..6910e9168 --- /dev/null +++ b/test/datagen/kotlin/noprimary-init.kt @@ -0,0 +1,9 @@ +class Constructors { + init { + println("Init block") + } + + constructor(i: Int) { + println("Constructor $i") + } +} diff --git a/test/datagen/kotlin/noprimary.json b/test/datagen/kotlin/noprimary.json new file mode 100644 index 000000000..3a40052be --- /dev/null +++ b/test/datagen/kotlin/noprimary.json @@ -0,0 +1,121 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Person", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "pets", + "variable_type": { + "name": "MutableList", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "mutableListOf" + } + } + ] + } + ], + "fields": [ + { + "name": "pets", + "variable_type": { + "name": "MutableList", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "mutableListOf" + } + } + ] + }, + { + "name": "Pet", + "kind": "CLASS", + "methods": [ + { + "name": "", + "arguments": [ + { + "name": "owner", + "variable_type": { + "name": "Person", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "owner" + } + ], + "variable": "pets" + } + ], + "method": "add", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "this" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/noprimary.kt b/test/datagen/kotlin/noprimary.kt new file mode 100644 index 000000000..4363cf31d --- /dev/null +++ b/test/datagen/kotlin/noprimary.kt @@ -0,0 +1,7 @@ +class Person(val pets: MutableList = mutableListOf()) + +class Pet { + constructor(owner: Person) { + owner.pets.add(this) // adds this pet to the list of its owner's pets + } +} diff --git a/test/datagen/kotlin/not-null-operator.json b/test/datagen/kotlin/not-null-operator.json new file mode 100644 index 000000000..c6a1636a6 --- /dev/null +++ b/test/datagen/kotlin/not-null-operator.json @@ -0,0 +1,76 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "x", + "variable_type": { + "name": "T?", + "kind": "OTHER" + } + }, + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "OP_NOTNULL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "OP_NOTNULL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "is_postfix": true + } + ], + "variable": "z" + } + ], + "is_postfix": true + } + ], + "variable": "prop" + } + }, + { + "name": "q", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "OP_NOTNULL", + "expressions": [ + { + "kind": "PAREN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ], + "is_postfix": true + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/not-null-operator.kt b/test/datagen/kotlin/not-null-operator.kt new file mode 100644 index 000000000..d19d7ab4e --- /dev/null +++ b/test/datagen/kotlin/not-null-operator.kt @@ -0,0 +1,3 @@ +var x: T? +val y = x!!.z!!.prop +val q = (x)!! diff --git a/test/datagen/kotlin/object-decl.json b/test/datagen/kotlin/object-decl.json new file mode 100644 index 000000000..2792c7999 --- /dev/null +++ b/test/datagen/kotlin/object-decl.json @@ -0,0 +1,117 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "Greeter", + "kind": "SINGLETON", + "methods": [ + { + "name": "greet", + "arguments": [ + { + "name": "greeted", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"Hello \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "bar" + } + ], + "literal": "\"${bar}\"" + }, + { + "kind": "TEMPLATE", + "literal": "\"!\"" + } + ], + "literal": "\"Hello ${bar}!\"" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "C", + "kind": "CLASS", + "methods": [ + { + "name": "getObject", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "expression": { + "kind": "NEW", + "anon_declaration": { + "name": "", + "kind": "SINGLETON", + "fields": [ + { + "name": "x", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"x\"" + } + } + ] + } + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/object-decl.kt b/test/datagen/kotlin/object-decl.kt new file mode 100644 index 000000000..8bd476318 --- /dev/null +++ b/test/datagen/kotlin/object-decl.kt @@ -0,0 +1,13 @@ +package boa.kotlin.test + +object Greeter { + fun greet(greeted: String) { + println("Hello ${bar}!") + } +} + +class C { + private fun getObject() = object { + val x: String = "x" + } +} diff --git a/test/datagen/kotlin/primary-init.json b/test/datagen/kotlin/primary-init.json new file mode 100644 index 000000000..95d6e9478 --- /dev/null +++ b/test/datagen/kotlin/primary-init.json @@ -0,0 +1,218 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "InitOrderDemo", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "name", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"First initializer block that prints \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "name" + } + ], + "literal": "\"${name}\"" + } + ], + "literal": "\"First initializer block that prints ${name}\"" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"Second initializer block that prints \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "name" + } + ], + "variable": "length" + } + ], + "literal": "\"${name.length}\"" + } + ], + "literal": "\"Second initializer block that prints ${name.length}\"" + } + ] + } + ] + } + ] + } + ] + } + ], + "fields": [ + { + "name": "firstProperty", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"First property: \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "name" + } + ], + "literal": "\"$name\"" + } + ], + "literal": "\"First property: $name\"" + } + ], + "method": "also", + "method_args": [ + { + "kind": "METHOD_REFERENCE", + "method": "println" + } + ] + } + }, + { + "name": "secondProperty", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"Second property: \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "name" + } + ], + "variable": "length" + } + ], + "literal": "\"${name.length}\"" + } + ], + "literal": "\"Second property: ${name.length}\"" + } + ], + "method": "also", + "method_args": [ + { + "kind": "METHOD_REFERENCE", + "method": "println" + } + ] + } + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/primary-init.kt b/test/datagen/kotlin/primary-init.kt new file mode 100644 index 000000000..f01f7b450 --- /dev/null +++ b/test/datagen/kotlin/primary-init.kt @@ -0,0 +1,13 @@ +class InitOrderDemo(name: String) { + val firstProperty = "First property: $name".also(::println) + + init { + println("First initializer block that prints ${name}") + } + + val secondProperty = "Second property: ${name.length}".also(::println) + + init { + println("Second initializer block that prints ${name.length}") + } +} diff --git a/test/datagen/kotlin/primary-secondary-init.json b/test/datagen/kotlin/primary-secondary-init.json new file mode 100644 index 000000000..bc30c8299 --- /dev/null +++ b/test/datagen/kotlin/primary-secondary-init.json @@ -0,0 +1,124 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "Constructors", + "kind": "CLASS", + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "s", + "variable_type": { + "name": "String", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "name": "", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"Init block\"" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "", + "arguments": [ + { + "name": "i", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"Constructor \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "i" + } + ], + "literal": "\"$i\"" + } + ], + "literal": "\"Constructor $i\"" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/primary-secondary-init.kt b/test/datagen/kotlin/primary-secondary-init.kt new file mode 100644 index 000000000..fcd547efe --- /dev/null +++ b/test/datagen/kotlin/primary-secondary-init.kt @@ -0,0 +1,9 @@ +class Constructors(s: String) { + init { + println("Init block") + } + + constructor(i: Int) { + println("Constructor $i") + } +} diff --git a/test/datagen/kotlin/property-dots.json b/test/datagen/kotlin/property-dots.json new file mode 100644 index 000000000..8469ef5e5 --- /dev/null +++ b/test/datagen/kotlin/property-dots.json @@ -0,0 +1,62 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "bar" + } + ], + "variable": "foo" + } + ], + "variable": "bar" + } + }, + { + "name": "foo", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "bar" + } + ], + "variable": "foo" + } + ], + "variable": "bar" + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/property-dots.kt b/test/datagen/kotlin/property-dots.kt new file mode 100644 index 000000000..0bc2fc3d9 --- /dev/null +++ b/test/datagen/kotlin/property-dots.kt @@ -0,0 +1,2 @@ +val foo = bar.foo.bar +val foo: Int = bar.foo.bar diff --git a/test/datagen/kotlin/ranged-for.json b/test/datagen/kotlin/ranged-for.json new file mode 100644 index 000000000..be17b2933 --- /dev/null +++ b/test/datagen/kotlin/ranged-for.json @@ -0,0 +1,242 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "i" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "i" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "5" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ], + "variable_declarations": [ + { + "name": "i", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "j" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "60" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ], + "literal": "downTo" + } + ], + "variable_declarations": [ + { + "name": "j", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "j" + } + ] + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "60" + }, + { + "kind": "LITERAL", + "literal": "3" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ], + "literal": "downTo" + } + ], + "variable_declarations": [ + { + "name": "j", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/ranged-for.kt b/test/datagen/kotlin/ranged-for.kt new file mode 100644 index 000000000..1b79eb85d --- /dev/null +++ b/test/datagen/kotlin/ranged-for.kt @@ -0,0 +1,14 @@ +fun f() { + for (i in 1..5) { + println(i) + } + for (i in 1..5 step 5) { + println(i) + } + for (j in 60 downTo 3) { + println(j) + } + for (j in 60 downTo 3 step 3) { + println(j) + } +} diff --git a/test/datagen/kotlin/safe-access.json b/test/datagen/kotlin/safe-access.json new file mode 100644 index 000000000..bc032c86c --- /dev/null +++ b/test/datagen/kotlin/safe-access.json @@ -0,0 +1,168 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "variable": "z", + "safe": true + } + ], + "variable": "q", + "safe": true + } + ], + "method": "m", + "safe": true + } + }, + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "variable": "z" + } + ], + "variable": "q" + } + ], + "method": "m", + "safe": true + } + }, + { + "name": "z", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "variable": "z", + "safe": true + } + ], + "variable": "q" + } + ], + "method": "m" + } + }, + { + "name": "m", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "variable": "z", + "safe": true + } + ], + "method": "q" + } + ], + "method": "m", + "safe": true + } + }, + { + "name": "n", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "expressions": [ + { + "kind": "METHODCALL", + "method": "y" + } + ], + "variable": "z", + "safe": true + } + ], + "method": "q" + } + ], + "method": "m", + "safe": true + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/safe-access.kt b/test/datagen/kotlin/safe-access.kt new file mode 100644 index 000000000..654ef59e3 --- /dev/null +++ b/test/datagen/kotlin/safe-access.kt @@ -0,0 +1,6 @@ +val x = y?.z?.q?.m() +val y = y.z.q?.m() +val z = y?.z.q.m() + +val m = y?.z.q()?.m() +val n = y()?.z.q()?.m() diff --git a/test/datagen/kotlin/string-template.json b/test/datagen/kotlin/string-template.json new file mode 100644 index 000000000..bc93bf685 --- /dev/null +++ b/test/datagen/kotlin/string-template.json @@ -0,0 +1,123 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "baz", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"test\"" + } + }, + { + "name": "bar", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"test: \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo" + } + ], + "literal": "\"$foo\"" + }, + { + "kind": "TEMPLATE", + "literal": "\" --> \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "n" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ], + "literal": "\"${n + 5}\"" + } + ], + "literal": "\"test: $foo --> ${n + 5}\"" + } + }, + { + "name": "bar", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"test: \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "foo" + } + ], + "literal": "\"$foo\"" + }, + { + "kind": "TEMPLATE", + "literal": "\" --> \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "OP_ADD", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "n" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ], + "literal": "\"${n + 5}\"" + } + ], + "literal": "\"\"\"test: $foo --> ${n + 5}\"\"\"" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/string-template.kt b/test/datagen/kotlin/string-template.kt new file mode 100644 index 000000000..21b5086f5 --- /dev/null +++ b/test/datagen/kotlin/string-template.kt @@ -0,0 +1,3 @@ +val baz = "test" +val bar = "test: $foo --> ${n + 5}" +val bar = """test: $foo --> ${n + 5}""" diff --git a/test/datagen/kotlin/super-type-is-generic.json b/test/datagen/kotlin/super-type-is-generic.json new file mode 100644 index 000000000..4fb151520 --- /dev/null +++ b/test/datagen/kotlin/super-type-is-generic.json @@ -0,0 +1,25 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "List", + "kind": "CLASS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "Cons", + "kind": "CLASS" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/super-type-is-generic.kt b/test/datagen/kotlin/super-type-is-generic.kt new file mode 100644 index 000000000..b78b27e64 --- /dev/null +++ b/test/datagen/kotlin/super-type-is-generic.kt @@ -0,0 +1,4 @@ +package boa.kotlin.test + +class List: Cons { +} \ No newline at end of file diff --git a/test/datagen/kotlin/super-type.json b/test/datagen/kotlin/super-type.json new file mode 100644 index 000000000..55375e669 --- /dev/null +++ b/test/datagen/kotlin/super-type.json @@ -0,0 +1,119 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "Derived", + "kind": "CLASS", + "parents": [ + { + "name": "Base", + "kind": "CLASS" + }, + { + "name": "Foo", + "kind": "CLASS" + } + ], + "methods": [ + { + "name": "", + "modifiers": [ + { + "kind": "OTHER", + "other": "primary" + } + ], + "arguments": [ + { + "name": "p", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "Foo", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "p" + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "TEMPLATE", + "literal": "\"P is \"" + }, + { + "kind": "TEMPLATE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "p" + } + ], + "literal": "\"${p}\"" + }, + { + "kind": "TEMPLATE", + "literal": "\".\"" + } + ], + "literal": "\"P is ${p}.\"" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/super-type.kt b/test/datagen/kotlin/super-type.kt new file mode 100644 index 000000000..aed9d9793 --- /dev/null +++ b/test/datagen/kotlin/super-type.kt @@ -0,0 +1,7 @@ +package boa.kotlin.test + +class Derived(p: Int) : Base, Foo(p) { + fun foo() { + println("P is ${p}.") + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/throw.json b/test/datagen/kotlin/throw.json new file mode 100644 index 000000000..99d7dfbb4 --- /dev/null +++ b/test/datagen/kotlin/throw.json @@ -0,0 +1,95 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "TRY", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "THROW", + "expressions": [ + { + "kind": "METHODCALL", + "method": "Exception", + "method_args": [ + { + "kind": "LITERAL", + "literal": "\"Foo\"" + } + ] + } + ] + } + ] + }, + { + "kind": "CATCH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "quux" + } + ] + } + ], + "variable_declarations": [ + { + "name": "e", + "variable_type": { + "name": "Exception", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "FINALLY", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "baz" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/throw.kt b/test/datagen/kotlin/throw.kt new file mode 100644 index 000000000..dc4ce2d3c --- /dev/null +++ b/test/datagen/kotlin/throw.kt @@ -0,0 +1,13 @@ +package boa.kotlin.test + +class C { + fun foo() { + try { + throw Exception("Foo") + } catch (e: Exception) { + quux() + } finally { + baz() + } + } +} \ No newline at end of file diff --git a/test/datagen/kotlin/try-catch.json b/test/datagen/kotlin/try-catch.json new file mode 100644 index 000000000..493e2fb3d --- /dev/null +++ b/test/datagen/kotlin/try-catch.json @@ -0,0 +1,134 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "methods": [ + { + "name": "foo", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "TRY", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "bar" + } + ] + } + ] + }, + { + "kind": "CATCH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "quux" + } + ] + } + ], + "variable_declarations": [ + { + "name": "e", + "variable_type": { + "name": "Exception", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "FINALLY", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "baz" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "f", + "return_type": { + "name": "Int", + "kind": "OTHER" + }, + "expression": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "TRY", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + ] + }, + { + "kind": "FINALLY", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + } + ] + } + ] + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/try-catch.kt b/test/datagen/kotlin/try-catch.kt new file mode 100644 index 000000000..da3b73225 --- /dev/null +++ b/test/datagen/kotlin/try-catch.kt @@ -0,0 +1,19 @@ +package boa.kotlin.test + +class C { + fun foo() { + try { + bar() + } catch (e: Exception) { + quux() + } finally { + baz() + } + } + + fun f(): Int = try { + 3 + } finally { + 5 + } +} diff --git a/test/datagen/kotlin/type-alias-generic.json b/test/datagen/kotlin/type-alias-generic.json new file mode 100644 index 000000000..9da9ce08b --- /dev/null +++ b/test/datagen/kotlin/type-alias-generic.json @@ -0,0 +1,41 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "FileTable", + "kind": "ALIAS", + "generic_parameters": [ + { + "name": "K", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "MutableMap>", + "kind": "OTHER" + } + ] + }, + { + "name": "Predicate", + "kind": "ALIAS", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "parents": [ + { + "name": "(T) -> Boolean", + "kind": "OTHER" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/type-alias-generic.kt b/test/datagen/kotlin/type-alias-generic.kt new file mode 100644 index 000000000..562b59b6e --- /dev/null +++ b/test/datagen/kotlin/type-alias-generic.kt @@ -0,0 +1,3 @@ +typealias FileTable = MutableMap> + +typealias Predicate = (T) -> Boolean \ No newline at end of file diff --git a/test/datagen/kotlin/type-casts.json b/test/datagen/kotlin/type-casts.json new file mode 100644 index 000000000..4ce16a0d6 --- /dev/null +++ b/test/datagen/kotlin/type-casts.json @@ -0,0 +1,99 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "foo", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "String", + "kind": "OTHER" + } + } + }, + { + "name": "bar", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "CAST", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "String", + "kind": "OTHER" + }, + "safe": true + } + }, + { + "name": "baz", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "String", + "kind": "OTHER" + } + } + }, + { + "name": "quux", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "String", + "kind": "OTHER" + } + } + ] + } + } + ] + } + ] +} diff --git a/test/datagen/kotlin/type-casts.kt b/test/datagen/kotlin/type-casts.kt new file mode 100644 index 000000000..d76b7e292 --- /dev/null +++ b/test/datagen/kotlin/type-casts.kt @@ -0,0 +1,5 @@ +val foo = y as String +val bar = y as? String + +val baz = y is String +val quux = y !is String \ No newline at end of file diff --git a/test/datagen/kotlin/type-constraints-val-field-in-class.json b/test/datagen/kotlin/type-constraints-val-field-in-class.json new file mode 100644 index 000000000..e69de29bb diff --git a/test/datagen/kotlin/type-constraints-val-field-in-class.kt b/test/datagen/kotlin/type-constraints-val-field-in-class.kt new file mode 100644 index 000000000..5aa516c39 --- /dev/null +++ b/test/datagen/kotlin/type-constraints-val-field-in-class.kt @@ -0,0 +1,6 @@ +class foo { + val c + where T: B, + T : T, + T : D +} diff --git a/test/datagen/kotlin/type-test.json b/test/datagen/kotlin/type-test.json new file mode 100644 index 000000000..3e346b7bf --- /dev/null +++ b/test/datagen/kotlin/type-test.json @@ -0,0 +1,129 @@ +{ + "namespaces": [ + { + "name": "", + "variables": [ + { + "name": "y", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "\"foo\"" + } + }, + { + "name": "x", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ], + "conditions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "String", + "kind": "OTHER" + } + } + ] + } + ] + } + }, + { + "name": "z", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "IF", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ], + "conditions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "TYPECOMPARE", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ], + "new_type": { + "name": "String", + "kind": "OTHER" + } + } + ] + } + ] + } + ] + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/type-test.kt b/test/datagen/kotlin/type-test.kt new file mode 100644 index 000000000..800cd1b62 --- /dev/null +++ b/test/datagen/kotlin/type-test.kt @@ -0,0 +1,3 @@ +val y = "foo" +val x = if (y is String) 3 else 5 +val z = if (y !is String) 3 else 5 diff --git a/test/datagen/kotlin/typealias.json b/test/datagen/kotlin/typealias.json new file mode 100644 index 000000000..1b245f261 --- /dev/null +++ b/test/datagen/kotlin/typealias.json @@ -0,0 +1,53 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "foo", + "kind": "ALIAS", + "parents": [ + { + "name": "Int", + "kind": "OTHER" + } + ] + }, + { + "name": "bar", + "kind": "ALIAS", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ], + "parents": [ + { + "name": "Int", + "kind": "OTHER" + } + ] + } + ], + "variables": [ + { + "name": "x", + "variable_type": { + "name": "foo", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "LITERAL", + "literal": "3" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/typealias.kt b/test/datagen/kotlin/typealias.kt new file mode 100644 index 000000000..e671428ee --- /dev/null +++ b/test/datagen/kotlin/typealias.kt @@ -0,0 +1,5 @@ +typealias foo = Int + +val x: foo = 3 + +private typealias bar = Int diff --git a/test/datagen/kotlin/varargs.json b/test/datagen/kotlin/varargs.json new file mode 100644 index 000000000..76efc0673 --- /dev/null +++ b/test/datagen/kotlin/varargs.json @@ -0,0 +1,200 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "asList", + "return_type": { + "name": "List", + "kind": "OTHER" + }, + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "arguments": [ + { + "name": "ts", + "variable_type": { + "name": "T", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + }, + { + "kind": "OTHER", + "other": "vararg" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "VARDECL", + "variable_decls": [ + { + "name": "result", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "generic_parameters": [ + { + "name": "T", + "kind": "GENERIC" + } + ], + "method": "ArrayList" + } + } + ] + } + ] + }, + { + "kind": "FOREACH", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + } + ], + "method": "add", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "t" + } + ] + } + ] + } + ], + "initializations": [ + { + "kind": "VARACCESS", + "variable": "ts" + } + ], + "variable_declarations": [ + { + "name": "t", + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ] + }, + { + "kind": "RETURN", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "result" + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "a", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "arrayOf", + "method_args": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "2" + }, + { + "kind": "LITERAL", + "literal": "3" + } + ] + } + }, + { + "name": "list", + "modifiers": [ + { + "kind": "FINAL" + } + ], + "initializer": { + "kind": "METHODCALL", + "method": "asList", + "method_args": [ + { + "kind": "OP_SUB", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + } + ] + }, + { + "kind": "LITERAL", + "literal": "0" + }, + { + "kind": "OP_MULT", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "a" + } + ] + }, + { + "kind": "LITERAL", + "literal": "4" + } + ] + } + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/varargs.kt b/test/datagen/kotlin/varargs.kt new file mode 100644 index 000000000..edf9a1047 --- /dev/null +++ b/test/datagen/kotlin/varargs.kt @@ -0,0 +1,8 @@ +fun asList(vararg ts: T): List { + val result = ArrayList() + for (t in ts) // ts is an Array + result.add(t) + return result +} +val a = arrayOf(1, 2, 3) +val list = asList(-1, 0, *a, 4) diff --git a/test/datagen/kotlin/visibilities.json b/test/datagen/kotlin/visibilities.json new file mode 100644 index 000000000..32094c7d1 --- /dev/null +++ b/test/datagen/kotlin/visibilities.json @@ -0,0 +1,54 @@ +{ + "namespaces": [ + { + "name": "", + "declarations": [ + { + "name": "C", + "kind": "CLASS", + "fields": [ + { + "name": "x", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PRIVATE" + } + ] + }, + { + "name": "y", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PUBLIC" + } + ] + }, + { + "name": "z", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "PROTECTED" + } + ] + }, + { + "name": "w", + "modifiers": [ + { + "kind": "VISIBILITY", + "visibility": "INTERNAL" + } + ] + }, + { + "name": "q" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/datagen/kotlin/visibilities.kt b/test/datagen/kotlin/visibilities.kt new file mode 100644 index 000000000..21b3771a5 --- /dev/null +++ b/test/datagen/kotlin/visibilities.kt @@ -0,0 +1,7 @@ +class C { + private var x + public var y + protected var z + internal var w + var q +} diff --git a/test/datagen/kotlin/when.json b/test/datagen/kotlin/when.json new file mode 100644 index 000000000..3779ff5fb --- /dev/null +++ b/test/datagen/kotlin/when.json @@ -0,0 +1,368 @@ +{ + "namespaces": [ + { + "name": "", + "methods": [ + { + "name": "f", + "return_type": { + "name": "Unit", + "kind": "OTHER" + }, + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "TYPECOMPARE", + "new_type": { + "name": "Int", + "kind": "OTHER" + } + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "IN", + "expressions": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"foo\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "DEFAULT" + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + ], + "variables": [ + { + "name": "x", + "initializer": { + "kind": "STATEMENT", + "statements": [ + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "3" + } + ] + }, + { + "kind": "SWITCH", + "statements": [ + { + "kind": "CASE", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "TYPECOMPARE", + "new_type": { + "name": "Int", + "kind": "OTHER" + } + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LOGICAL_NOT", + "expressions": [ + { + "kind": "IN", + "expressions": [ + { + "kind": "ARRAY_COMPREHENSION", + "expressions": [ + { + "kind": "LITERAL", + "literal": "1" + }, + { + "kind": "LITERAL", + "literal": "5" + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + }, + { + "kind": "CASE", + "expressions": [ + { + "kind": "LITERAL", + "literal": "\"foo\"" + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "DEFAULT" + }, + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + }, + { + "kind": "DEFAULT" + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "print", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "y" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + } + ] + } + ] +} + diff --git a/test/datagen/kotlin/when.kt b/test/datagen/kotlin/when.kt new file mode 100644 index 000000000..a90cd05f2 --- /dev/null +++ b/test/datagen/kotlin/when.kt @@ -0,0 +1,28 @@ +fun f() : Unit { + when (x) { + is Int -> print(x) + in 1..5 -> { + print(x) + print(x) + } + "foo" -> print(x) + else -> { + print(x) + } + } +} + +var x = when(x) { + 3 -> when (x) { + !is Int -> print(x) + !in 1..5 -> { + print(x) + print(x) + } + "foo" -> print(x) + else -> { + print(x) + } + } + else -> print(y) +} diff --git a/test/datagen/kotlin/while.json b/test/datagen/kotlin/while.json new file mode 100644 index 000000000..8c3d63a67 --- /dev/null +++ b/test/datagen/kotlin/while.json @@ -0,0 +1,161 @@ +{ + "namespaces": [ + { + "name": "boa.kotlin.test", + "methods": [ + { + "name": "foo", + "return_type": { + "name": "Unit", + "kind": "OTHER" + }, + "arguments": [ + { + "name": "x", + "variable_type": { + "name": "Int", + "kind": "OTHER" + }, + "modifiers": [ + { + "kind": "IMPLICIT" + }, + { + "kind": "FINAL" + } + ] + } + ], + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "WHILE", + "statements": [ + { + "kind": "BLOCK", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + }, + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "OP_INC", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ], + "is_postfix": true + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "LTEQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "7" + } + ] + } + ] + }, + { + "kind": "WHILE", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "METHODCALL", + "method": "println", + "method_args": [ + { + "kind": "VARACCESS", + "variable": "x" + } + ] + } + ] + } + ], + "conditions": [ + { + "kind": "EQ", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "x" + }, + { + "kind": "LITERAL", + "literal": "7" + } + ] + } + ] + }, + { + "kind": "WHILE", + "statements": [ + { + "kind": "EXPRESSION", + "expressions": [ + { + "kind": "EMPTY" + } + ] + } + ], + "conditions": [ + { + "kind": "METHODCALL", + "expressions": [ + { + "kind": "VARACCESS", + "variable": "mutableList" + } + ], + "method": "remove", + "method_args": [ + { + "kind": "LITERAL", + "literal": "2" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} diff --git a/test/datagen/kotlin/while.kt b/test/datagen/kotlin/while.kt new file mode 100644 index 000000000..1fcfede1f --- /dev/null +++ b/test/datagen/kotlin/while.kt @@ -0,0 +1,11 @@ +package boa.kotlin.test + +fun foo(x: Int) : Unit { + while (x <= 7) { + println(x) + x++ + } + while (x == 7) + println(x) + while (mutableList.remove(2)); +}