diff --git a/analysis/common/api/arrow-analysis-common.api b/analysis/common/api/arrow-analysis-common.api index 56161ac2..fab4fdfa 100644 --- a/analysis/common/api/arrow-analysis-common.api +++ b/analysis/common/api/arrow-analysis-common.api @@ -112,6 +112,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/SpecialKin public static final field Pre Larrow/meta/plugins/analysis/phases/analysis/solver/SpecialKind; public static final field TrustBlock Larrow/meta/plugins/analysis/phases/analysis/solver/SpecialKind; public static final field TrustCall Larrow/meta/plugins/analysis/phases/analysis/solver/SpecialKind; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/SpecialKind; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/SpecialKind; } @@ -142,6 +143,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/contex public static final field Completed Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnalysisResult; public static final field ParsingError Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnalysisResult; public static final field Retry Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnalysisResult; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnalysisResult; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnalysisResult; } @@ -214,6 +216,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/contex public static final field DELEGATION Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/CallableMemberDescriptor$Kind; public static final field FAKE_OVERRIDE Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/CallableMemberDescriptor$Kind; public static final field SYNTHESIZED Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/CallableMemberDescriptor$Kind; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/CallableMemberDescriptor$Kind; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/CallableMemberDescriptor$Kind; } @@ -245,6 +248,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/contex public static final field ENUM_ENTRY Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ClassDescriptor$ClassKind; public static final field INTERFACE Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ClassDescriptor$ClassKind; public static final field OBJECT Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ClassDescriptor$ClassKind; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ClassDescriptor$ClassKind; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ClassDescriptor$ClassKind; } @@ -396,6 +400,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/contex public static final field FINAL Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/Modality; public static final field OPEN Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/Modality; public static final field SEALED Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/Modality; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/Modality; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/Modality; } @@ -645,6 +650,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/contex public static final field PROPERTY_SETTER Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/AnnotationUseSiteTarget; public static final field RECEIVER Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/AnnotationUseSiteTarget; public static final field SETTER_PARAMETER Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/AnnotationUseSiteTarget; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/AnnotationUseSiteTarget; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/AnnotationUseSiteTarget; } @@ -1049,6 +1055,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/contex public static final field NONE Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ProjectionKind; public static final field OUT Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ProjectionKind; public static final field STAR Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ProjectionKind; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ProjectionKind; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ProjectionKind; } @@ -1212,6 +1219,7 @@ public abstract interface class arrow/meta/plugins/analysis/phases/analysis/solv public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeCastExpresionKind : java/lang/Enum { public static final field POSITIVE_TYPE_CAST Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeCastExpresionKind; public static final field QUESTION_TYPE_CAST Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeCastExpresionKind; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeCastExpresionKind; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeCastExpresionKind; } @@ -1366,6 +1374,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/contex public static final field In Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Variance; public static final field Invariant Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Variance; public static final field Out Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Variance; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Variance; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Variance; } @@ -1452,6 +1461,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/check/mode public final class arrow/meta/plugins/analysis/phases/analysis/solver/check/model/ControlFlowFn$ReturnBehavior : java/lang/Enum { public static final field RETURNS_ARGUMENT Larrow/meta/plugins/analysis/phases/analysis/solver/check/model/ControlFlowFn$ReturnBehavior; public static final field RETURNS_BLOCK_RESULT Larrow/meta/plugins/analysis/phases/analysis/solver/check/model/ControlFlowFn$ReturnBehavior; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/check/model/ControlFlowFn$ReturnBehavior; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/check/model/ControlFlowFn$ReturnBehavior; } @@ -1525,6 +1535,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/check/mode public final class arrow/meta/plugins/analysis/phases/analysis/solver/check/model/LoopPlace : java/lang/Enum { public static final field AFTER_LOOP Larrow/meta/plugins/analysis/phases/analysis/solver/check/model/LoopPlace; public static final field INSIDE_LOOP Larrow/meta/plugins/analysis/phases/analysis/solver/check/model/LoopPlace; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/check/model/LoopPlace; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/check/model/LoopPlace; } @@ -1688,6 +1699,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/errors/Err public final class arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Exception : java/lang/Enum, arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds { public static final field IllegalState Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Exception; public static final field OtherException Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Exception; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public fun getFullDescription ()Ljava/lang/String; public fun getId ()Ljava/lang/String; public fun getLevel ()Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; @@ -1704,6 +1716,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/errors/Err public static final field InconsistentDefaultValues Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Inconsistency; public static final field InconsistentInvariants Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Inconsistency; public synthetic fun (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public static fun getEntries ()Lkotlin/enums/EnumEntries; public fun getFullDescription ()Ljava/lang/String; public fun getId ()Ljava/lang/String; public fun getLevel ()Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; @@ -1718,6 +1731,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/errors/Err public static final field LawMustCallFunction Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Laws; public static final field LawMustHaveParametersInOrder Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Laws; public static final field SubjectWithoutName Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Laws; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public fun getFullDescription ()Ljava/lang/String; public fun getId ()Ljava/lang/String; public fun getLevel ()Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; @@ -1731,6 +1745,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/errors/Err public static final field NotStrongerPostcondition Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Liskov; public static final field NotWeakerPrecondition Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Liskov; public synthetic fun (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public static fun getEntries ()Lkotlin/enums/EnumEntries; public fun getFullDescription ()Ljava/lang/String; public fun getId ()Ljava/lang/String; public fun getLevel ()Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; @@ -1744,6 +1759,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/errors/Err public static final field UnexpectedFieldInitBlock Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Parsing; public static final field UnexpectedReference Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Parsing; public static final field WarningParsingPredicate Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Parsing; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public fun getFullDescription ()Ljava/lang/String; public fun getId ()Ljava/lang/String; public fun getLevel ()Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; @@ -1758,6 +1774,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/errors/Err public static final field UnsatCallPre Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Unsatisfiability; public static final field UnsatInvariants Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Unsatisfiability; public synthetic fun (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public static fun getEntries ()Lkotlin/enums/EnumEntries; public fun getFullDescription ()Ljava/lang/String; public fun getId ()Ljava/lang/String; public fun getLevel ()Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; @@ -1768,6 +1785,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/errors/Err public final class arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Unsupported : java/lang/Enum, arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds { public static final field UnsupportedExpression Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds$Unsupported; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public fun getFullDescription ()Ljava/lang/String; public fun getId ()Ljava/lang/String; public fun getLevel ()Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; @@ -1810,6 +1828,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/errors/Sev public static final field Info Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; public static final field Unsupported Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; public static final field Warning Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/errors/SeverityLevel; } @@ -2054,6 +2073,7 @@ public final class arrow/meta/plugins/analysis/types/PrimitiveType : java/lang/E public static final field INTEGRAL Larrow/meta/plugins/analysis/types/PrimitiveType; public static final field RATIONAL Larrow/meta/plugins/analysis/types/PrimitiveType; public static final field STRING Larrow/meta/plugins/analysis/types/PrimitiveType; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/types/PrimitiveType; public static fun values ()[Larrow/meta/plugins/analysis/types/PrimitiveType; } diff --git a/analysis/common/src/main/kotlin/arrow/meta/continuations/ContSeq.kt b/analysis/common/src/main/kotlin/arrow/meta/continuations/ContSeq.kt index b448b669..08ba1704 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/continuations/ContSeq.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/continuations/ContSeq.kt @@ -122,14 +122,14 @@ inline fun doOnlyWhen(condition: Boolean, crossinline f: () -> ContSeq): C inline fun doOnlyWhen( condition: Boolean, value: A, - crossinline f: () -> ContSeq + crossinline f: () -> ContSeq, ): ContSeq = if (condition) f() else cont { value } /** Execute a side effect only when some condition holds. */ inline fun doOnlyWhenNotNull( thing: T?, value: A, - crossinline f: (T) -> ContSeq + crossinline f: (T) -> ContSeq, ): ContSeq { return if (thing != null) f(thing) else cont { value } } @@ -155,13 +155,16 @@ sealed interface ContSyntax { @RestrictsSuspension sealed interface ContSeqSyntax : ContSyntax { suspend fun yield(value: A) + suspend fun yieldAll(iterator: Iterator) + suspend fun yieldAll(elements: Iterable) { if (elements is Collection && elements.isEmpty()) return return yieldAll(elements.iterator()) } suspend fun yieldAll(sequence: Sequence) = yieldAll(sequence.iterator()) + suspend fun yieldAll(sequence: ContSeq) = yieldAll(sequence.iterator()) } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/DescriptorUtils.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/DescriptorUtils.kt index 2a8093ab..cfebb910 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/DescriptorUtils.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/DescriptorUtils.kt @@ -122,8 +122,11 @@ fun DeclarationDescriptor.gather( object : MemberScope { override fun getClassifierNames(): Set = throw IllegalStateException("not available here") + override fun getFunctionNames(): Set = throw IllegalStateException("not available here") + override fun getVariableNames(): Set = throw IllegalStateException("not available here") + override fun getContributedDescriptors( filter: (name: String) -> Boolean ): List = @@ -159,7 +162,7 @@ fun DeclarationDescriptor.gather( fun ModuleDescriptor.gather( initialPackages: List = listOf(FqName("")), addSubPackages: Boolean, - predicate: (DeclarationDescriptor) -> Boolean + predicate: (DeclarationDescriptor) -> Boolean, ): List { // initialize worklists val packagesWorklist = LinkedList(initialPackages) @@ -203,7 +206,7 @@ fun ModuleDescriptor.gather( /** Rename the conditions from one descriptor to the names of another */ internal fun Solver.renameConditions( constraints: DeclarationConstraints, - to: DeclarationDescriptor + to: DeclarationDescriptor, ): DeclarationConstraints { val fromParams = (constraints.descriptor as? CallableDescriptor)?.valueParameters?.map { it.name.value } @@ -216,7 +219,7 @@ internal fun Solver.renameConditions( to, constraints.pre, constraints.post, - constraints.doNotLookAtArgumentsWhen + constraints.doNotLookAtArgumentsWhen, ) } } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/Primitive.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/Primitive.kt index 9f34e7d9..007b6eb1 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/Primitive.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/Primitive.kt @@ -42,7 +42,7 @@ import org.sosy_lab.java_smt.api.NumeralFormula fun Solver.primitiveFormula( context: ResolutionContext, resolvedCall: ResolvedCall, - args: List + args: List, ): Formula? { val descriptor = resolvedCall.resultingDescriptor val returnTy = descriptor.returnType?.primitiveType() @@ -69,7 +69,7 @@ private val comparisonNames: List = "<", "<=", "==", - "!=" + "!=", ) .map { FqName(it) } @@ -79,7 +79,7 @@ internal fun CallableDescriptor.isComparison() = private fun Solver.comparisonFormula( context: ResolutionContext, resolvedCall: ResolvedCall, - args: List + args: List, ): BooleanFormula? = resolvedCall .allArgumentExpressions(context) @@ -126,7 +126,7 @@ private fun Solver.comparisonFormula( private fun Solver.booleanFormula( descriptor: CallableDescriptor, - args: List + args: List, ): BooleanFormula? = when (descriptor.fqNameSafe) { FqName("kotlin.Boolean.not"), @@ -141,7 +141,7 @@ private fun Solver.booleanFormula( private fun Solver.integralFormula( descriptor: CallableDescriptor, - args: List + args: List, ): NumeralFormula.IntegerFormula? = when (descriptor.name.value) { "plus" -> intPlus(args) @@ -171,7 +171,7 @@ private fun Solver.integralFormula( private fun Solver.rationalFormula( descriptor: CallableDescriptor, - args: List + args: List, ): NumeralFormula.RationalFormula? = when (descriptor.name.value) { "plus" -> rationalPlus(args) diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ResolvedCallUtils.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ResolvedCallUtils.kt index 69e205d8..01d56898 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ResolvedCallUtils.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ResolvedCallUtils.kt @@ -17,7 +17,7 @@ enum class SpecialKind { Invariant, TrustCall, TrustBlock, - NotLookArgs + NotLookArgs, } internal val ResolvedCall.specialKind: SpecialKind? @@ -67,7 +67,7 @@ data class ArgumentExpression( val type: Type, val isVarArg: Boolean, val isSpread: Boolean, - val expression: List + val expression: List, ) /** @@ -84,7 +84,7 @@ internal fun ResolvedCall.allArgumentExpressions( it, isVarArg = false, isSpread = false, - listOfNotNull(getReceiverExpression()) + listOfNotNull(getReceiverExpression()), ) } ) + valueArgumentExpressions(context) @@ -120,7 +120,7 @@ internal fun ResolvedCall.valueArgumentExpressions( containingType, isVarArg = param.varargElementType != null, isSpread = false, - listOf(defaultValue) + listOf(defaultValue), ) } else -> @@ -129,7 +129,7 @@ internal fun ResolvedCall.valueArgumentExpressions( containingType, isVarArg = param.varargElementType != null, isSpread = resolvedArg.arguments.singleOrNull()?.isSpread ?: false, - resolvedArg.arguments.mapNotNull { it.argumentExpression } + resolvedArg.arguments.mapNotNull { it.argumentExpression }, ) } } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/ResolutionContext.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/ResolutionContext.kt index ca92045f..905f42a1 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/ResolutionContext.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/ResolutionContext.kt @@ -14,11 +14,17 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.errors.ErrorIds interface ResolutionContext { val types: Types + fun handleError(error: ErrorIds, element: Element, msg: String): Unit + fun type(typeReference: TypeReference?): Type? + fun Element.constraintsDSLElements(): List + fun descriptorFor(fqName: FqName): List + fun descriptorFor(declaration: Declaration): DeclarationDescriptor? + fun backingPropertyForConstructorParameter( parameter: ValueParameterDescriptor ): PropertyDescriptor? diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/ResolvedCall.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/ResolvedCall.kt index 1a86ca67..61252b93 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/ResolvedCall.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/ResolvedCall.kt @@ -11,8 +11,11 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.types.Type interface ResolvedCall { val callElement: Element + fun getReceiverExpression(): Expression? + fun getReturnType(): Type + val dispatchReceiver: ReceiverValue? val extensionReceiver: ReceiverValue? val resultingDescriptor: CallableDescriptor diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnalysisResult.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnalysisResult.kt index 33d7518a..76866ab2 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnalysisResult.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnalysisResult.kt @@ -3,5 +3,5 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.descripto enum class AnalysisResult { Retry, Completed, - ParsingError + ParsingError, } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnnotationDescriptor.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnnotationDescriptor.kt index 9d443609..c6a7deaf 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnnotationDescriptor.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/AnnotationDescriptor.kt @@ -8,6 +8,7 @@ interface AnnotationDescriptor { val allValueArguments: Map fun argumentValueAsString(argName: String): String? + fun argumentValueAsArrayOfString(argName: String): List val fqName: FqName? diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/CallableMemberDescriptor.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/CallableMemberDescriptor.kt index cca653a5..7177e446 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/CallableMemberDescriptor.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/CallableMemberDescriptor.kt @@ -7,6 +7,6 @@ interface CallableMemberDescriptor : CallableDescriptor, MemberDescriptor { DECLARATION, FAKE_OVERRIDE, DELEGATION, - SYNTHESIZED + SYNTHESIZED, } } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ClassDescriptor.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ClassDescriptor.kt index 8d089ed5..96ed0e42 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ClassDescriptor.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ClassDescriptor.kt @@ -33,6 +33,6 @@ interface ClassDescriptor : DeclarationDescriptor, ClassifierDescriptorWithTypeP ENUM_CLASS, ENUM_ENTRY, ANNOTATION_CLASS, - OBJECT + OBJECT, } } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/DeclarationDescriptor.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/DeclarationDescriptor.kt index 0276f91d..9db0be62 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/DeclarationDescriptor.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/DeclarationDescriptor.kt @@ -6,7 +6,10 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.F interface DeclarationDescriptor : Named, Annotated { val containingDeclaration: DeclarationDescriptor? val containingPackage: FqName? + fun element(): Element? + val fqNameSafe: FqName + fun impl(): Any } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/MemberScope.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/MemberScope.kt index 0922ff09..2fded711 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/MemberScope.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/MemberScope.kt @@ -14,8 +14,11 @@ interface MemberScope { class CombinedMemberScope(private val scopes: Collection) : MemberScope { override fun getClassifierNames(): Set = scopes.flatMap { it.getClassifierNames() }.toSet() + override fun getFunctionNames(): Set = scopes.flatMap { it.getFunctionNames() }.toSet() + override fun getVariableNames(): Set = scopes.flatMap { it.getVariableNames() }.toSet() + override fun getContributedDescriptors( filter: (name: String) -> Boolean ): List = diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/Modality.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/Modality.kt index 65d910e7..d6736b98 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/Modality.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/Modality.kt @@ -4,5 +4,5 @@ enum class Modality { FINAL, SEALED, OPEN, - ABSTRACT + ABSTRACT, } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ModuleDescriptor.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ModuleDescriptor.kt index 072d1a51..59c420e8 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ModuleDescriptor.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ModuleDescriptor.kt @@ -5,6 +5,8 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.N interface ModuleDescriptor : DeclarationDescriptor { fun getPackage(pck: String): PackageViewDescriptor? + fun getSubPackagesOf(fqName: FqName): List + val stableName: Name? } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/TypeAliasConstructorDescriptor.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/TypeAliasConstructorDescriptor.kt index 2aca498d..aa8f89a5 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/TypeAliasConstructorDescriptor.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/TypeAliasConstructorDescriptor.kt @@ -2,5 +2,6 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.descripto interface TypeAliasConstructorDescriptor : ConstructorDescriptor { val underlyingConstructorDescriptor: ConstructorDescriptor + fun getContainingDeclaration(): TypeAliasDescriptor } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ValueParameterDescriptor.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ValueParameterDescriptor.kt index 482ac4b5..a9b03a39 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ValueParameterDescriptor.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ValueParameterDescriptor.kt @@ -8,6 +8,8 @@ interface ValueParameterDescriptor : VariableDescriptor, ParameterDescriptor { val isCrossinline: Boolean val isNoinline: Boolean val varargElementType: Type? + fun declaresDefaultValue(): Boolean + val defaultValue: Expression? } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Annotated.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Annotated.kt index d04c0fdc..0ee1d08e 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Annotated.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Annotated.kt @@ -2,5 +2,6 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface Annotated : Element { fun getAnnotations(): List + val annotationEntries: List } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/AnnotationUseSiteTarget.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/AnnotationUseSiteTarget.kt index 9093c7b4..eca1ba20 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/AnnotationUseSiteTarget.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/AnnotationUseSiteTarget.kt @@ -9,5 +9,5 @@ enum class AnnotationUseSiteTarget { RECEIVER, CONSTRUCTOR_PARAMETER, SETTER_PARAMETER, - PROPERTY_DELEGATE_FIELD + PROPERTY_DELEGATE_FIELD, } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Class.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Class.kt index b3ad1ffd..d91a170c 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Class.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Class.kt @@ -2,11 +2,18 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface Class : ClassOrObject { fun getProperties(): List + fun isInterface(): Boolean + fun isEnum(): Boolean + fun isData(): Boolean + fun isSealed(): Boolean + fun isInner(): Boolean + fun isInline(): Boolean + fun isValue(): Boolean } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ClassOrObject.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ClassOrObject.kt index b241f0b4..022464bd 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ClassOrObject.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ClassOrObject.kt @@ -2,7 +2,10 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface ClassOrObject : NamedDeclaration, PureClassOrObject { fun getAnonymousInitializers(): List + fun isTopLevel(): Boolean + fun getPrimaryConstructorParameterList(): ParameterList? = primaryConstructor?.valueParameterList + fun isAnnotation(): Boolean } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/DeclarationWithBody.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/DeclarationWithBody.kt index 5701a07f..475a2405 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/DeclarationWithBody.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/DeclarationWithBody.kt @@ -2,9 +2,13 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface DeclarationWithBody : Declaration { val bodyExpression: Expression? + fun hasBlockBody(): Boolean + fun hasBody(): Boolean + fun hasDeclaredReturnType(): Boolean + fun body(): Expression? val valueParameters: List diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/DeclarationWithInitializer.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/DeclarationWithInitializer.kt index 1b33add2..6a2ccc96 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/DeclarationWithInitializer.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/DeclarationWithInitializer.kt @@ -2,5 +2,6 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface DeclarationWithInitializer : Declaration { val initializer: Expression? + fun hasInitializer(): Boolean } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Element.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Element.kt index df252ec7..a492871d 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Element.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Element.kt @@ -6,9 +6,14 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.descriptor interface Element : PureElement { val text: String + fun impl(): Any + fun getResolvedCall(context: ResolutionContext): ResolvedCall? + fun getVariableDescriptor(context: ResolutionContext): VariableDescriptor? + fun parents(): List + fun location(): CompilerMessageSourceLocation? } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Expression.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Expression.kt index a34e6fad..d2d35016 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Expression.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Expression.kt @@ -5,5 +5,6 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.types.Type interface Expression : Element { fun type(context: ResolutionContext): Type? + fun lastBlockStatementOrThis(): Expression } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ExpressionWithLabel.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ExpressionWithLabel.kt index c7dfcd71..463503ea 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ExpressionWithLabel.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ExpressionWithLabel.kt @@ -2,6 +2,8 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface ExpressionWithLabel : Expression { fun getTargetLabel(): SimpleNameExpression? + fun getLabelName(): String? + fun getLabelNameAsName(): Name? } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/FunctionLiteral.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/FunctionLiteral.kt index 22eb9180..0cbb4578 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/FunctionLiteral.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/FunctionLiteral.kt @@ -2,5 +2,6 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface FunctionLiteral : Function { fun hasParameterSpecification(): Boolean + override val bodyExpression: Expression? } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/LambdaExpression.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/LambdaExpression.kt index 2958e94a..d8592518 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/LambdaExpression.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/LambdaExpression.kt @@ -4,5 +4,6 @@ interface LambdaExpression : Expression { val functionLiteral: FunctionLiteral val valueParameters: List val bodyExpression: Expression? + fun hasDeclaredReturnType(): Boolean } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ObjectDeclaration.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ObjectDeclaration.kt index 74b58331..6e43d45f 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ObjectDeclaration.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ObjectDeclaration.kt @@ -2,5 +2,6 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface ObjectDeclaration : ClassOrObject { fun isCompanion(): Boolean + fun isObjectLiteral(): Boolean } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Parameter.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Parameter.kt index 05bc316e..a4469050 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Parameter.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Parameter.kt @@ -2,10 +2,13 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface Parameter : CallableDeclaration { fun hasDefaultValue(): Boolean + val defaultValue: Expression? val isMutable: Boolean val isVarArg: Boolean + fun hasValOrVar(): Boolean + val destructuringDeclaration: DestructuringDeclaration? val isLoopParameter: Boolean val isCatchParameter: Boolean diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ProjectionKind.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ProjectionKind.kt index f3bd5e52..6034d085 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ProjectionKind.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ProjectionKind.kt @@ -4,5 +4,5 @@ enum class ProjectionKind { IN, OUT, STAR, - NONE + NONE, } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Property.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Property.kt index 95fe0866..3c87dae8 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Property.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Property.kt @@ -7,11 +7,18 @@ interface Property : VariableDeclaration { val accessors: List val getter: PropertyAccessor? val setter: PropertyAccessor? + fun hasDelegate(): Boolean + val delegate: PropertyDelegate? + fun hasDelegateExpression(): Boolean + val delegateExpression: Expression? + fun hasDelegateExpressionOrInitializer(): Boolean + val delegateExpressionOrInitializer: Expression? + fun hasBody(): Boolean } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/PureClassOrObject.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/PureClassOrObject.kt index b747b79a..9cbb9045 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/PureClassOrObject.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/PureClassOrObject.kt @@ -7,8 +7,11 @@ interface PureClassOrObject : PureElement, DeclarationContainer { val superTypeListEntries: List val companionObjects: List + fun hasExplicitPrimaryConstructor(): Boolean + fun hasPrimaryConstructor(): Boolean + val primaryConstructor: PrimaryConstructor? val primaryConstructorModifierList: ModifierList? diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/SimpleNameExpression.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/SimpleNameExpression.kt index 5a582a90..a513cbe7 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/SimpleNameExpression.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/SimpleNameExpression.kt @@ -2,5 +2,6 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface SimpleNameExpression : ReferenceExpression { fun getReferencedName(): String + fun getReferencedNameAsName(): Name } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeAlias.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeAlias.kt index d5d3a602..65d9ebdd 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeAlias.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeAlias.kt @@ -2,5 +2,6 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface TypeAlias : NamedDeclaration { fun isTopLevel(): Boolean + fun getTypeReference(): TypeReference? } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeCastExpression.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeCastExpression.kt index 1ca68fae..8bb27dbe 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeCastExpression.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/TypeCastExpression.kt @@ -2,7 +2,7 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements enum class TypeCastExpresionKind { POSITIVE_TYPE_CAST, - QUESTION_TYPE_CAST + QUESTION_TYPE_CAST, } interface TypeCastExpression : OperationExpression { diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ValueArgument.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ValueArgument.kt index 21b3151e..787b6328 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ValueArgument.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/ValueArgument.kt @@ -2,6 +2,8 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements interface ValueArgument : ExpressionResolvedValueArgument { fun getArgumentName(): ValueArgumentName? + fun isNamed(): Boolean + fun isExternal(): Boolean } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Type.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Type.kt index e2d4fa7a..6dafa95f 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Type.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Type.kt @@ -9,19 +9,33 @@ interface Type : Comparable { val arguments: List fun isBoolean(): Boolean + fun isNullable(): Boolean + fun isSubtypeOf(other: Type): Boolean + fun isEqualTo(other: Type): Boolean + fun isInt(): Boolean + fun isLong(): Boolean + fun isFloat(): Boolean + fun isDouble(): Boolean + fun isTypeParameter(): Boolean + fun isAnyOrNullableAny(): Boolean + fun isByte(): Boolean + fun isShort(): Boolean + fun isUnsignedNumberType(): Boolean + fun isChar(): Boolean + fun isString(): Boolean override fun compareTo(other: Type): Int = diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Variance.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Variance.kt index e02e1c8c..b4917388 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Variance.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Variance.kt @@ -3,5 +3,5 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.types enum class Variance { In, Out, - Invariant + Invariant, } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Declarations.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Declarations.kt index 50c73f6f..30e2f297 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Declarations.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Declarations.kt @@ -61,7 +61,7 @@ internal fun SolverState.checkTopLevel( declaration: Declaration, isConstructor: Boolean, resultName: ObjectFormula, - bodyCheck: (data: CheckData, checkPost: (finalData: CheckData) -> Unit) -> ContSeq + bodyCheck: (data: CheckData, checkPost: (finalData: CheckData) -> Unit) -> ContSeq, ): ContSeq = continuationBracket.flatMap { // bring the constraints in (if there are any) @@ -81,7 +81,7 @@ internal fun SolverState.checkTopLevel( THIS_VAR_NAME, descriptor.constructedClass.defaultType, declaration, - true + true, ) else -> (descriptor.extensionReceiverParameter ?: descriptor.dispatchReceiverParameter)?.let { @@ -116,7 +116,7 @@ internal fun SolverState.checkTopLevel( context, ReturnPoints.new(declaration, resultName), CurrentVarInfo(initialVarInfo), - CurrentBranch.new() + CurrentBranch.new(), ) ContSeq.unit @@ -141,7 +141,7 @@ internal fun SolverState.checkTopLevel( isConstructor, finalData.context, declaration, - finalData.branch.get() + finalData.branch.get(), ) } } @@ -151,7 +151,7 @@ internal fun SolverState.checkTopLevelDeclarationWithBody( context: ResolutionContext, descriptor: DeclarationDescriptor, declaration: Declaration, - body: Expression? + body: Expression?, ): ContSeq = checkTopLevel(context, descriptor, declaration, isConstructor = false, solver.resultVariable) { data, @@ -167,7 +167,7 @@ internal fun SolverState.checkTopLevelDeclarationWithBody( internal fun SolverState.checkPrimaryConstructor( context: ResolutionContext, descriptor: DeclarationDescriptor, - declaration: PrimaryConstructor + declaration: PrimaryConstructor, ): ContSeq = checkTopLevel(context, descriptor, declaration, isConstructor = true, solver.thisVariable) { data, @@ -177,14 +177,14 @@ internal fun SolverState.checkPrimaryConstructor( declaration.getContainingClassOrObject(), declaration.bodyExpression, data, - checkPost + checkPost, ) } internal fun SolverState.checkImplicitPrimaryConstructor( context: ResolutionContext, descriptor: DeclarationDescriptor, - klass: ClassOrObject + klass: ClassOrObject, ): ContSeq = checkTopLevel(context, descriptor, klass, isConstructor = true, solver.thisVariable) { data, @@ -197,7 +197,7 @@ internal fun SolverState.postPrimaryConstructor( klass: ClassOrObject, bodyExpression: Expression?, data: CheckData, - checkPost: (finalData: CheckData) -> Unit + checkPost: (finalData: CheckData) -> Unit, ): ContSeq = ContSeq.unit .flatMap { @@ -214,14 +214,14 @@ internal fun SolverState.postPrimaryConstructor( checkClassDeclarationInConstructorContext( solver.thisVariable, klass.declarations, - finalState.data + finalState.data, ) .onEach { checkPost(finalState.data) } } private fun SolverState.introduceImplicitProperties( context: ResolutionContext, - klass: ClassOrObject + klass: ClassOrObject, ): ContSeq = cont { // if we have 'var' or 'var' in the parameters, // we need to assign them to fields @@ -239,11 +239,11 @@ private fun SolverState.introduceImplicitProperties( solver.objects { equal( solver.makeObjectVariable(paramName), - field(propertyDescriptor, solver.thisVariable) + field(propertyDescriptor, solver.thisVariable), ) - } + }, ), - context + context, ) } } @@ -252,7 +252,7 @@ private fun SolverState.introduceImplicitProperties( private fun SolverState.checkSuperTypeEntries( context: ResolutionContext, superTypeListEntries: List, - data: CheckData + data: CheckData, ): ContSeq = superTypeListEntries .mapNotNull { entry -> @@ -273,7 +273,7 @@ private fun SolverState.checkSuperTypeEntries( private fun SolverState.checkClassDeclarationInConstructorContext( thisRef: ObjectFormula, declarations: List, - data: CheckData + data: CheckData, ): ContSeq = declarations .map { decl -> @@ -294,7 +294,7 @@ private fun SolverState.checkClassDeclarationInConstructorContext( internal fun SolverState.checkSecondaryConstructor( context: ResolutionContext, descriptor: DeclarationDescriptor, - declaration: SecondaryConstructor + declaration: SecondaryConstructor, ): ContSeq = checkTopLevel(context, descriptor, declaration, isConstructor = true, solver.thisVariable) { data, @@ -314,7 +314,7 @@ internal fun SolverState.checkSecondaryConstructor( checkExpressionConstraints( solver.thisVariable, declaration.bodyExpression, - stateAfterPrimaryConstructorCall.data + stateAfterPrimaryConstructorCall.data, ) .map { finalState -> checkPost(finalState.data) } } @@ -323,7 +323,7 @@ internal fun SolverState.checkSecondaryConstructor( internal fun SolverState.checkEnumEntry( context: ResolutionContext, descriptor: DeclarationDescriptor, - entry: EnumEntry + entry: EnumEntry, ): ContSeq = checkTopLevel(context, descriptor, entry, isConstructor = false, solver.thisVariable) { data, @@ -343,7 +343,7 @@ internal fun SolverState.checkEnumEntry( private fun SolverState.checkLiskovConditions( declaration: Declaration, descriptor: DeclarationDescriptor, - context: ResolutionContext + context: ResolutionContext, ): Boolean { val immediateConstraints = getImmediateConstraintsFor(descriptor) val overriddenConstraints = getOverriddenConstraintsFor(descriptor) @@ -370,7 +370,7 @@ private fun SolverState.checkLiskovConditions( /** Check that the values of default parameters satisfy the preconditions */ private fun SolverState.checkDefaultParameters( declaration: Declaration, - data: CheckData + data: CheckData, ): ContSeq = when (declaration) { is DeclarationWithBody -> diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/EntryPoint.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/EntryPoint.kt index 6aad5f6b..8df72abc 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/EntryPoint.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/EntryPoint.kt @@ -50,7 +50,7 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.state.SolverState public fun SolverState.checkDeclarationConstraints( context: ResolutionContext, declaration: Declaration, - descriptor: DeclarationDescriptor + descriptor: DeclarationDescriptor, ) { if (!hadParseErrors() && declaration.shouldBeAnalyzed() && descriptor.shouldBeAnalyzed()) { // trace @@ -70,7 +70,7 @@ public fun SolverState.checkDeclarationConstraints( checkImplicitPrimaryConstructor( context, descriptor.constructors.single { it.isPrimary }, - declaration + declaration, ) } is Property -> @@ -80,14 +80,14 @@ public fun SolverState.checkDeclarationConstraints( context, descriptor, declaration, - declaration.stableBody() + declaration.stableBody(), ) declaration.delegate != null -> checkTopLevelDeclarationWithBody( context, descriptor, declaration, - declaration.delegate?.expression + declaration.delegate?.expression, ) declaration.getter != null || declaration.setter != null -> { // no body, maybe we have getter and setter @@ -100,7 +100,7 @@ public fun SolverState.checkDeclarationConstraints( context, getterDescr, getterDecl, - getterDecl.body() + getterDecl.body(), ) } } @@ -112,7 +112,7 @@ public fun SolverState.checkDeclarationConstraints( context, setterDescr, setterDecl, - setterDecl.body() + setterDecl.body(), ) } } @@ -125,7 +125,7 @@ public fun SolverState.checkDeclarationConstraints( context, descriptor, declaration, - declaration.stableBody() + declaration.stableBody(), ) }.drain() } catch (e: IllegalStateException) { diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Expressions.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Expressions.kt index 27c13f8e..318dcb47 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Expressions.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Expressions.kt @@ -129,14 +129,14 @@ import org.sosy_lab.java_smt.api.BooleanFormula internal fun SolverState.checkExpressionConstraints( associatedVarName: String, expression: Expression?, - data: CheckData + data: CheckData, ): ContSeq = checkExpressionConstraints(solver.makeObjectVariable(associatedVarName), expression, data) internal fun SolverState.checkExpressionConstraintsWithNewName( prefix: String, expression: Expression?, - data: CheckData + data: CheckData, ): ContSeq = checkExpressionConstraints(newName(data.context, prefix, expression), expression, data) @@ -146,7 +146,7 @@ internal fun SolverState.checkExpressionConstraintsWithNewName( internal fun SolverState.checkExpressionConstraints( associatedVarName: ObjectFormula, expression: Expression?, - data: CheckData + data: CheckData, ): ContSeq = ContSeq.unit .map { @@ -171,7 +171,7 @@ internal fun SolverState.checkExpressionConstraints( associatedVarName, expression.statements, expression.implicitReturnFromLast, - data + data, ) } is ReturnExpression -> checkReturnConstraints(expression, data) @@ -210,7 +210,7 @@ internal fun SolverState.checkExpressionConstraints( associatedVarName, expression.subjectExpression, expression.computeConditions(), - data + data, ) is LoopExpression -> checkLoopExpression(expression, data) is FinallySection -> @@ -229,7 +229,7 @@ internal fun SolverState.checkExpressionConstraints( expression.isNegated, expression.typeReference, subjectName, - data + data, ) stateAfter } @@ -253,7 +253,7 @@ internal fun SolverState.checkExpressionConstraints( private fun SolverState.fallThrough( associatedVarName: ObjectFormula, expression: Expression, - data: CheckData + data: CheckData, ): ContSeq = when (val call = expression.getResolvedCall(data.context)) { // fall-through: treat as a call @@ -292,7 +292,7 @@ private fun SolverState.checkBlockExpression( associatedVarName: ObjectFormula, expressions: List, implicitReturnFromLast: Boolean, - data: CheckData + data: CheckData, ): ContSeq = when { expressions.isEmpty() -> data.noReturn {} @@ -329,7 +329,7 @@ private fun SolverState.checkBlockExpression( private fun SolverState.checkLabeledExpression( associatedVarName: ObjectFormula, expression: LabeledExpression, - data: CheckData + data: CheckData, ): ContSeq { val labelName = expression.getLabelName()!! // add the return point to the list and recur @@ -353,7 +353,7 @@ private fun SolverState.checkLabeledExpression( */ private fun SolverState.checkReturnConstraints( expression: ReturnExpression, - data: CheckData + data: CheckData, ): ContSeq { // figure out the right variable to assign // - if 'return@label', find the label in the recorded return points @@ -372,7 +372,7 @@ private fun SolverState.checkReturnConstraints( /** Checks a 'throw', by simply returning the type of the exception */ private fun SolverState.checkThrowConstraints( expression: ThrowExpression, - data: CheckData + data: CheckData, ): ContSeq { return checkExpressionConstraintsWithNewName("throw", expression.thrownExpression, data).map { stateAfter -> @@ -391,7 +391,7 @@ private fun SolverState.checkCallExpression( associatedVarName: ObjectFormula, expression: Expression, resolvedCall: ResolvedCall, - data: CheckData + data: CheckData, ): ContSeq { val specialKind = resolvedCall.specialKind val specialControlFlow = controlFlowAnyFunction(data.context, resolvedCall) @@ -403,13 +403,13 @@ private fun SolverState.checkCallExpression( checkExpressionConstraints( associatedVarName, resolvedCall.getReceiverOrThisNamedArgument(), - data + data, ) specialKind == SpecialKind.Invariant -> // ignore invariant arguments checkExpressionConstraints( associatedVarName, resolvedCall.getReceiverOrThisNamedArgument(), - data + data, ) specialKind == SpecialKind.TrustCall || specialKind == SpecialKind.TrustBlock -> { val arg = resolvedCall.valueArgumentExpressions(data.context).getOrNull(0) @@ -433,7 +433,7 @@ private fun SolverState.checkCallExpression( */ private fun controlFlowAnyFunction( context: ResolutionContext, - resolvedCall: ResolvedCall + resolvedCall: ResolvedCall, ): ControlFlowFn? { val thisElement = resolvedCall.singleArg("this", context) ?: resolvedCall.singleArg("receiver", context) @@ -448,7 +448,7 @@ private fun controlFlowAnyFunction( thisElement, bodyElement, argumentName, - ControlFlowFn.ReturnBehavior.RETURNS_ARGUMENT + ControlFlowFn.ReturnBehavior.RETURNS_ARGUMENT, ) } FqName("kotlin.apply") -> @@ -456,7 +456,7 @@ private fun controlFlowAnyFunction( thisElement, bodyElement, "this", - ControlFlowFn.ReturnBehavior.RETURNS_ARGUMENT + ControlFlowFn.ReturnBehavior.RETURNS_ARGUMENT, ) FqName("kotlin.let") -> { val argumentName = blockElement.valueParameters.getOrNull(0)?.nameAsName?.value ?: "it" @@ -464,7 +464,7 @@ private fun controlFlowAnyFunction( thisElement, bodyElement, argumentName, - ControlFlowFn.ReturnBehavior.RETURNS_BLOCK_RESULT + ControlFlowFn.ReturnBehavior.RETURNS_BLOCK_RESULT, ) } FqName("kotlin.run") -> @@ -472,14 +472,14 @@ private fun controlFlowAnyFunction( thisElement, bodyElement, "this", - ControlFlowFn.ReturnBehavior.RETURNS_BLOCK_RESULT + ControlFlowFn.ReturnBehavior.RETURNS_BLOCK_RESULT, ) FqName("kotlin.with") -> ControlFlowFn( thisElement, bodyElement, "this", - ControlFlowFn.ReturnBehavior.RETURNS_BLOCK_RESULT + ControlFlowFn.ReturnBehavior.RETURNS_BLOCK_RESULT, ) else -> null } @@ -492,7 +492,7 @@ private fun controlFlowAnyFunction( null /* thisElement == null */, bodyElement, "this", - ControlFlowFn.ReturnBehavior.RETURNS_BLOCK_RESULT + ControlFlowFn.ReturnBehavior.RETURNS_BLOCK_RESULT, ) else -> null } @@ -507,7 +507,7 @@ private fun SolverState.checkControlFlowFunctionCall( associatedVarName: ObjectFormula, wholeExpr: Expression, info: ControlFlowFn, - data: CheckData + data: CheckData, ): ContSeq { val thisName = when (info.returnBehavior) { @@ -527,7 +527,7 @@ private fun SolverState.checkControlFlowFunctionCall( null, thisName, info.target, - data + data, ) { newData -> inScope(newData) { // add the name to the context, @@ -544,7 +544,7 @@ private fun SolverState.checkControlFlowFunctionCall( checkExpressionConstraints( returnName, info.body, - newData.addVarInfos(listOfNotNull(newVarInfo)) + newData.addVarInfos(listOfNotNull(newVarInfo)), ) } } @@ -555,7 +555,7 @@ internal fun SolverState.checkRegularFunctionCall( associatedVarName: ObjectFormula, resolvedCall: ResolvedCall, expression: Expression, - data: CheckData + data: CheckData, ): ContSeq { val receiverExpr = resolvedCall.getReceiverExpression() val referencedArg = resolvedCall.referencedArg(receiverExpr) @@ -567,7 +567,7 @@ internal fun SolverState.checkRegularFunctionCall( resolvedCall, receiverName, receiverExpr, // - data + data, ) { dataAfterReceiver -> val callConstraints = getConstraintsFor(resolvedCall) ?: primitiveConstraints(data.context, resolvedCall) @@ -585,10 +585,10 @@ internal fun SolverState.checkRegularFunctionCall( doNotLook.map { c -> NamedConstraint( c.msg, - solver.substituteObjectVariables(c.formula, mapOf(THIS_VAR_NAME to receiverName)) + solver.substituteObjectVariables(c.formula, mapOf(THIS_VAR_NAME to receiverName)), ) } - addAndCheckConsistency(renamedNotLook, data.context) { /* do nothing on failure */} + addAndCheckConsistency(renamedNotLook, data.context) { /* do nothing on failure */ } val dataAfterNotLook = dataAfterReceiver.addBranch(renamedNotLook.map(NamedConstraint::formula)) // 2. introduce the postconditions @@ -602,7 +602,7 @@ internal fun SolverState.checkRegularFunctionCall( receiverName, resolvedCall.getReturnType(), expression, - dataAfterNotLook + dataAfterNotLook, ) } else { // introduce the fact that we are looking at the arguments, if present @@ -615,12 +615,12 @@ internal fun SolverState.checkRegularFunctionCall( solver.not( solver.substituteObjectVariables( c.formula, - mapOf(THIS_VAR_NAME to receiverName) + mapOf(THIS_VAR_NAME to receiverName), ) - ) + ), ) } - addAndCheckConsistency(renamedNotLook, data.context) { /* do nothing on failure */} + addAndCheckConsistency(renamedNotLook, data.context) { /* do nothing on failure */ } dataAfterReceiver.addBranch(renamedNotLook.map(NamedConstraint::formula)) } else dataAfterReceiver // regular case, check the arguments and move on normally @@ -641,7 +641,7 @@ internal fun SolverState.checkRegularFunctionCall( dataAfterArgs.context, expression, resolvedCall, - dataAfterArgs.branch.get() + dataAfterArgs.branch.get(), ) } }, @@ -649,9 +649,9 @@ internal fun SolverState.checkRegularFunctionCall( receiverName, resolvedCall.getReturnType(), expression, - dataAfterArgs + dataAfterArgs, ) - } + }, ) } } @@ -664,7 +664,7 @@ internal fun SolverState.checkVariableAsFunctionCall( descriptor: VariableDescriptor, receiverExpr: Expression?, expression: Expression, - data: CheckData + data: CheckData, ): ContSeq { val receiverName = solver.makeObjectVariable(newName(data.context, THIS_VAR_NAME, receiverExpr)) val callConstraints = getConstraintsFor(descriptor) @@ -678,7 +678,7 @@ internal fun SolverState.checkVariableAsFunctionCall( receiverName, descriptor.type, expression, - data + data, ) } @@ -693,7 +693,7 @@ private fun SolverState.checkCallableDescriptor( receiverName: ObjectFormula, returnType: Type, expression: Expression, - data: CheckData + data: CheckData, ): ContSeq = ContSeq.unit.map { // rename with the arguments @@ -712,7 +712,7 @@ private fun SolverState.checkCallableDescriptor( val argName = if (hasReceiver) receiverName else argVars[0].assignedSmtVariable NamedConstraint( "${expression.text} == ${descriptor.fqNameSafe.name}($argName)", - equal(associatedVarName, field(descriptor, argName)) + equal(associatedVarName, field(descriptor, argName)), ) } addConstraint(fieldConstraint, data.context) @@ -721,7 +721,7 @@ private fun SolverState.checkCallableDescriptor( if (!returnType.isNullable()) { addConstraint( NamedConstraint("$associatedVarName is not null", solver.isNotNull(associatedVarName)), - data.context + data.context, ) } // there's no point in continuing if we are in an inconsistent position @@ -730,7 +730,7 @@ private fun SolverState.checkCallableDescriptor( callConstraints, data.context, expression, - data.branch.get() + data.branch.get(), ) ensure(!inconsistentPostConditions) data.noReturn() @@ -744,7 +744,7 @@ private fun SolverState.checkReceiverWithPossibleSafeDot( receiverName: ObjectFormula, receiverExpr: Expression?, data: CheckData, - block: (CheckData) -> ContSeq + block: (CheckData) -> ContSeq, ): ContSeq = when { (receiverExpr != null) && (receiverExpr.impl() == wholeExpr.impl()) -> { @@ -781,7 +781,7 @@ private fun SolverState.checkReceiverWithPossibleSafeDot( val nullResult = NamedConstraint( "$associatedVarName is null (?.)", - solver.isNull(associatedVarName) + solver.isNull(associatedVarName), ) val inconsistent = checkConditionsInconsistencies( @@ -789,7 +789,7 @@ private fun SolverState.checkReceiverWithPossibleSafeDot( dataAfterReceiver.context, receiverExpr!!, dataAfterReceiver.branch.get(), - reportIfInconsistent = false + reportIfInconsistent = false, ) ensure(!inconsistent) dataAfterReceiver.addBranch(solver.isNull(receiverName)).noReturn() @@ -800,7 +800,7 @@ private fun SolverState.checkReceiverWithPossibleSafeDot( val notNullCstr = NamedConstraint( "$receiverName is not null (?.)", - solver.isNotNull(receiverName) + solver.isNotNull(receiverName), ) val inconsistent = checkConditionsInconsistencies( @@ -808,7 +808,7 @@ private fun SolverState.checkReceiverWithPossibleSafeDot( data.context, rcv, dataAfterReceiver.branch.get(), - reportIfInconsistent = false + reportIfInconsistent = false, ) ensure(!inconsistent) dataAfterReceiver.addBranch(solver.isNotNull(receiverName)).noReturn() @@ -828,7 +828,7 @@ private fun SolverState.checkElvisOperator( associatedVarName: ObjectFormula, leftExpr: Expression, rightExpr: Expression, - data: CheckData + data: CheckData, ): ContSeq { val leftName = newName(data.context, "left", leftExpr) val left = solver.makeObjectVariable(leftName) @@ -849,7 +849,7 @@ private fun SolverState.checkElvisOperator( data.context, leftExpr, data.branch.get(), - reportIfInconsistent = false + reportIfInconsistent = false, ) ensure(!inconsistent) } @@ -858,7 +858,7 @@ private fun SolverState.checkElvisOperator( checkExpressionConstraints( associatedVarName, rightExpr, - stateAfterLeft.data.addBranch(solver.isNull(left)) + stateAfterLeft.data.addBranch(solver.isNull(left)), ) } } else { // the non-null case of ?: @@ -868,7 +868,7 @@ private fun SolverState.checkElvisOperator( val resultIsLeft = NamedConstraint( "$leftName is result of ?:", - solver.objects { equal(left, associatedVarName) } + solver.objects { equal(left, associatedVarName) }, ) val inconsistent = checkConditionsInconsistencies( @@ -876,7 +876,7 @@ private fun SolverState.checkElvisOperator( data.context, leftExpr, data.branch.get(), - reportIfInconsistent = false + reportIfInconsistent = false, ) ensure(!inconsistent) } @@ -891,7 +891,7 @@ private fun SolverState.checkAsOperator( kind: TypeCastExpresionKind, leftExpr: Expression?, whole: Expression, - data: CheckData + data: CheckData, ): ContSeq { val leftName = newName(data.context, "left", leftExpr) val left = solver.makeObjectVariable(leftName) @@ -914,7 +914,7 @@ private fun SolverState.checkAsOperator( data.context, whole, data.branch.get(), - reportIfInconsistent = false + reportIfInconsistent = false, ) ensure(!inconsistent) } @@ -931,7 +931,7 @@ private fun SolverState.checkAsOperator( data.context, whole, data.branch.get(), - reportIfInconsistent = false + reportIfInconsistent = false, ) ensure(!inconsistent) } @@ -943,7 +943,7 @@ private fun SolverState.checkAsOperator( internal data class CallArgumentsInfo( val returnOrVariables: Either>, - val data: CheckData + val data: CheckData, ) { internal companion object { fun init(data: CheckData) = CallArgumentsInfo(emptyList().right(), data) @@ -952,7 +952,7 @@ internal data class CallArgumentsInfo( internal data class CallVarArgumentsInfo( val returnOrVariables: Either>, - val data: CheckData + val data: CheckData, ) { internal companion object { fun init(data: CheckData) = CallVarArgumentsInfo(emptyList().right(), data) @@ -961,7 +961,7 @@ internal data class CallVarArgumentsInfo( internal data class CallArgumentVariable( val parameterName: String, - val assignedSmtVariable: ObjectFormula + val assignedSmtVariable: ObjectFormula, ) private fun List.toMap() = associate { (name, smt) -> name to smt } @@ -974,7 +974,7 @@ private fun List.toMap() = associate { (name, smt) -> name */ private fun SolverState.checkCallArguments( resolvedCall: ResolvedCall, - data: CheckData + data: CheckData, ): ContSeq { // why is this so complicated? // in theory, we just need to run checkExpressionConstraints over each argument @@ -988,7 +988,7 @@ private fun SolverState.checkCallArguments( // version for varargs fun accVarArg( upToNow: ContSeq, - expr: Expression + expr: Expression, ): ContSeq = upToNow.flatMap { (result, data) -> result.fold( @@ -1002,14 +1002,14 @@ private fun SolverState.checkCallArguments( }) { s -> cont { CallVarArgumentsInfo((argsUpToNow + listOf(argUniqueName)).right(), s.data) } } - } + }, ) } // version for regular parameters fun acc( upToNow: ContSeq, - current: ArgumentExpression + current: ArgumentExpression, ): ContSeq = upToNow.flatMap { (result, data) -> result.fold( @@ -1031,7 +1031,7 @@ private fun SolverState.checkCallArguments( .ints { equal( solver.intValue(field(sizeDecl, allArgsUniqueName)), - makeNumber(maybeMultipleExpr.size.toLong()) + makeNumber(maybeMultipleExpr.size.toLong()), ) } .let { addConstraint(NamedConstraint("vararg length", it), data.context) } @@ -1039,10 +1039,10 @@ private fun SolverState.checkCallArguments( // return as usual CallArgumentsInfo( (argsUpToNow + listOf(CallArgumentVariable(name, allArgsUniqueName))).right(), - data + data, ) } - } + }, ) } } else { @@ -1056,12 +1056,12 @@ private fun SolverState.checkCallArguments( cont { CallArgumentsInfo( (argsUpToNow + listOf(CallArgumentVariable(name, argUniqueName))).right(), - s.data + s.data, ) } } } - } + }, ) } @@ -1072,12 +1072,12 @@ private fun SolverState.checkCallArguments( private fun SolverState.checkNullExpression( associatedVarName: ObjectFormula, - data: CheckData + data: CheckData, ): ContSeq = data.noReturn { addConstraint( NamedConstraint("$associatedVarName is null (== null)", solver.isNull(associatedVarName)), - data.context + data.context, ) } @@ -1088,7 +1088,7 @@ private fun SolverState.checkNullExpression( private fun SolverState.checkConstantExpression( associatedVarName: ObjectFormula, expression: ConstantExpression, - data: CheckData + data: CheckData, ): ContSeq = data.noReturn { val type = expression.type(data.context)?.unwrapIfNullable() @@ -1115,7 +1115,7 @@ private fun SolverState.checkConstantExpression( solver.ints { equal( solver.intValue(field(lengthDecl, associatedVarName)), - makeNumber(stringLiteral.length.toLong()) + makeNumber(stringLiteral.length.toLong()), ) } } @@ -1126,13 +1126,13 @@ private fun SolverState.checkConstantExpression( addConstraint( NamedConstraint( "${expression.text} checkConstantExpression $associatedVarName ${expression.text}", - it + it, ), - data.context + data.context, ) addConstraint( NamedConstraint("${expression.text} is not null", solver.isNotNull(associatedVarName)), - data.context + data.context, ) } } @@ -1140,7 +1140,7 @@ private fun SolverState.checkConstantExpression( private fun SolverState.checkStringTemplate( associatedVarName: ObjectFormula, expression: StringTemplateExpression, - data: CheckData + data: CheckData, ): ContSeq = expression.entries .filterIsInstance() @@ -1160,16 +1160,16 @@ private fun SolverState.checkStringTemplate( solver.ints { greaterOrEquals( solver.intValue(field(lengthDecl, associatedVarName)), - makeNumber(minimalLength.toLong()) + makeNumber(minimalLength.toLong()), ) - } + }, ), - data.context + data.context, ) } addConstraint( NamedConstraint("${expression.text} is not null", solver.isNotNull(associatedVarName)), - data.context + data.context, ) } } @@ -1182,7 +1182,7 @@ private fun Type.getField(fieldName: String): DeclarationDescriptor? = private fun SolverState.checkAssignmentExpression( expression: AssignmentExpression, - data: CheckData + data: CheckData, ): ContSeq { // in cases in which we don't do anything special @@ -1227,7 +1227,7 @@ private fun SolverState.checkAssignmentExpression( checkExpressionConstraints( field(leftDescr, solver.makeObjectVariable(info.smtName)), expression.right, - data + data, ) } } @@ -1235,15 +1235,14 @@ private fun SolverState.checkAssignmentExpression( } } else -> null - } - ?: onlyRhs() + } ?: onlyRhs() } /** Check special binary cases, and make the other fall-through */ private fun SolverState.checkBinaryExpression( associatedVarName: ObjectFormula, expression: BinaryExpression, - data: CheckData + data: CheckData, ): ContSeq { val operator = expression.operationTokenRpr val left = expression.left @@ -1262,7 +1261,7 @@ private fun SolverState.checkBinaryExpression( val cstr = solver.booleans { equivalence(solver.boolValue(associatedVarName), it) } addConstraint( NamedConstraint("$associatedVarName is null?", cstr), - stateAfter.data.context + stateAfter.data.context, ) } stateAfter @@ -1282,7 +1281,7 @@ private fun SolverState.checkBinaryExpression( }?.let { addConstraint( NamedConstraint("boolean operator $operator", it), - stateAfterRhs.data.context + stateAfterRhs.data.context, ) } stateAfterRhs @@ -1305,21 +1304,21 @@ private fun SolverState.checkIsExpression( isNegated: Boolean, typeReference: TypeReference?, subjectName: ObjectFormula, - data: CheckData + data: CheckData, ) { if (!isNegated) { val invariants = (data.context.type(typeReference)?.let { typeInvariants(it, subjectName, data.context) }) - // in the worst case, we know that it is not null - ?: listOf(NamedConstraint("$associatedVarName is not null", solver.isNotNull(subjectName))) + // in the worst case, we know that it is not null + ?: listOf(NamedConstraint("$associatedVarName is not null", solver.isNotNull(subjectName))) invariants.forEach { cstr -> val constraint = NamedConstraint( "$associatedVarName => ${cstr.msg}", solver.booleanFormulaManager.implication( solver.boolValue(associatedVarName), - cstr.formula - ) + cstr.formula, + ), ) addConstraint(constraint, data.context) } @@ -1337,7 +1336,7 @@ internal fun SolverState.checkLambda(expr: LambdaExpression, data: CheckData): C itParam, expr.functionLiteral.typeReference, expr.bodyExpression, - data + data, ) } @@ -1351,7 +1350,7 @@ internal fun Type.singleFunctionArgument() = /** Checks the body of a local function, but does nothing in particular with it */ private fun SolverState.checkFunctionDeclarationExpression( declaration: Function, - data: CheckData + data: CheckData, ): ContSeq = checkFunctionBody( declaration, @@ -1360,7 +1359,7 @@ private fun SolverState.checkFunctionDeclarationExpression( null, declaration.typeReference, declaration.stableBody(), - data + data, ) /** Shared code between lambda expressions and local function declarations */ @@ -1371,7 +1370,7 @@ internal fun SolverState.checkFunctionBody( itType: Type?, resultType: TypeReference?, body: Expression?, - data: CheckData + data: CheckData, ): ContSeq = // We need to introduce new arguments // and a new return point @@ -1406,7 +1405,7 @@ internal fun SolverState.checkFunctionBody( .addVarInfos(newParams) // add new names from arguments .replaceTopMostReturnPoint( null, - solver.makeObjectVariable(resultSmtName) + solver.makeObjectVariable(resultSmtName), ) // add the new return point data.noReturn { // and now go and check the body @@ -1422,7 +1421,7 @@ internal fun SolverState.checkFunctionBody( */ private fun SolverState.checkNonFunctionDeclarationExpression( declaration: Declaration, - data: CheckData + data: CheckData, ): ContSeq> = doOnlyWhenNotNull(declaration.stableBody(), Pair(null, data.noReturn())) { body -> val declName = @@ -1444,7 +1443,7 @@ private fun SolverState.checkNonFunctionDeclarationExpression( NamedConstraint("invariant in $declName", renamed), data.context, invBody, - data.branch.get() + data.branch.get(), ) ensure(!inconsistentInvariant) } @@ -1463,9 +1462,9 @@ private fun SolverState.checkNonFunctionDeclarationExpression( addConstraint( NamedConstraint( "$declName $smtName = $newVarName", - equal(solver.makeObjectVariable(smtName), solver.makeObjectVariable(newVarName)) + equal(solver.makeObjectVariable(smtName), solver.makeObjectVariable(newVarName)), ), - data.context + data.context, ) } } @@ -1483,7 +1482,7 @@ private fun SolverState.checkBodyAgainstInvariants( declName: String, invariant: BooleanFormula?, body: Expression?, - data: CheckData + data: CheckData, ): ContSeq> { val newName = newName(data.context, declName, body) return checkExpressionConstraints(newName, body, data) @@ -1495,7 +1494,7 @@ private fun SolverState.checkBodyAgainstInvariants( NamedConstraint("assignment to `${element.text}`", renamed), data.context, element, - data.branch.get() + data.branch.get(), ) } } @@ -1505,7 +1504,7 @@ private fun SolverState.checkBodyAgainstInvariants( private fun SolverState.obtainInvariant( expression: Expression, - data: CheckData + data: CheckData, ): Pair? = expression .getResolvedCall(data.context) @@ -1525,7 +1524,7 @@ private fun SolverState.obtainInvariant( private fun SolverState.checkNameExpression( associatedVarName: ObjectFormula, referencedName: String, - data: CheckData + data: CheckData, ): ContSeq = data.noReturn { // use the SMT name recorded in the variable info @@ -1534,7 +1533,7 @@ private fun SolverState.checkNameExpression( solver.objects { equal(associatedVarName, solver.makeObjectVariable(it.smtName)) } addConstraint( NamedConstraint("$associatedVarName = ${it.smtName} (name)", constraint), - data.context + data.context, ) } } @@ -1546,10 +1545,9 @@ private fun Expression.computeConditions(): List = val elseExpr = elseExpression ?: MissingElseBlockExpression(this, thenExpr) listOf( SimpleCondition(condition!!, false, thenExpr, thenExpr), - SimpleCondition(null, true, elseExpr, elseExpr) + SimpleCondition(null, true, elseExpr, elseExpr), ) - } - ?: emptyList() + } ?: emptyList() is WhenExpression -> { val subject = subjectExpression entries.flatMap { entry -> @@ -1575,7 +1573,7 @@ private fun SolverState.checkConditional( associatedVarName: ObjectFormula, subject: Expression?, branches: List, - data: CheckData + data: CheckData, ): ContSeq { val newSubjectVar = solver.makeObjectVariable(newName(data.context, "subject", subject)) // this handles the cases of when with a subject, and with 'val x = subject' @@ -1584,7 +1582,7 @@ private fun SolverState.checkConditional( checkNonFunctionDeclarationExpression(subject, data).map { (actualSubjectVar, stateAfter) -> Pair( actualSubjectVar?.let { solver.makeObjectVariable(it) } ?: newSubjectVar, - stateAfter.data + stateAfter.data, ) } else -> @@ -1605,9 +1603,9 @@ private fun SolverState.checkConditional( addConstraint( NamedConstraint( "check condition branch $conditionVar", - solver.makeBooleanObjectVariable(conditionVar) + solver.makeBooleanObjectVariable(conditionVar), ), - newData.context + newData.context, ) }) .map { returnInfo -> Pair(Pair(returnInfo, cond), conditionVar) } @@ -1630,7 +1628,7 @@ private fun SolverState.checkConditional( data.context, cond.whole, data.branch.get(), - reportIfInconsistent = true + reportIfInconsistent = true, ) // it only makes sense to continue if we are not consistent ensure(!inconsistentEnvironment) @@ -1649,7 +1647,7 @@ private fun SolverState.introduceCondition( conditionVar: ObjectFormula, subjectVar: ObjectFormula, cond: Condition, - data: CheckData + data: CheckData, ): ContSeq = when (cond) { is SimpleCondition -> checkExpressionConstraints(conditionVar, cond.predicate, data) @@ -1664,7 +1662,7 @@ private fun SolverState.introduceCondition( } addConstraint( NamedConstraint("$subjectVar is null (condition)", complete), - data.context + data.context, ) } } else { @@ -1675,21 +1673,21 @@ private fun SolverState.introduceCondition( solver.booleans { equivalence( solver.boolValue(subjectVar), - solver.makeBooleanObjectVariable(patternName) + solver.makeBooleanObjectVariable(patternName), ) } PrimitiveType.INTEGRAL -> solver.ints { equal( solver.intValue(subjectVar), - solver.makeIntegerObjectVariable(patternName) + solver.makeIntegerObjectVariable(patternName), ) } PrimitiveType.RATIONAL -> solver.rationals { equal( solver.decimalValue(subjectVar), - solver.makeDecimalObjectVariable(patternName) + solver.makeDecimalObjectVariable(patternName), ) } else -> null @@ -1697,7 +1695,7 @@ private fun SolverState.introduceCondition( val complete = solver.booleans { equivalence(solver.boolValue(conditionVar), it) } addConstraint( NamedConstraint("$subjectVar equals $patternName (condition)", complete), - data.context + data.context, ) } data.noReturn() @@ -1724,7 +1722,7 @@ private fun SolverState.yesNo( ): List>> { fun go( currents: List>, - acc: List + acc: List, ): List>> = if (currents.isEmpty()) { emptyList() @@ -1741,7 +1739,7 @@ private fun SolverState.yesNo( private fun SolverState.checkLoopExpression( expression: LoopExpression, - data: CheckData + data: CheckData, ): ContSeq = when (expression) { is ForExpression -> checkForExpression(expression.loopParameter, expression.body, data) @@ -1774,7 +1772,7 @@ private fun SolverState.checkLoopExpression( private fun SolverState.checkForExpression( loopParameter: Parameter?, body: Expression?, - data: CheckData + data: CheckData, ): ContSeq = ContSeq { yield(LoopPlace.INSIDE_LOOP) @@ -1804,7 +1802,7 @@ private fun SolverState.checkWhileExpression( condition: Expression, body: Expression?, afterBody: List, - data: CheckData + data: CheckData, ): ContSeq { val condName = newName(data.context, "cond", condition) return checkExpressionConstraints(condName, body, data) @@ -1826,7 +1824,7 @@ private fun SolverState.checkWhileExpression( data.context, condition, data.branch.get(), - reportIfInconsistent = true + reportIfInconsistent = true, ) checkLoopBody(body, afterBody, data.addBranch(objVar)) } @@ -1840,7 +1838,7 @@ private fun SolverState.checkWhileExpression( data.context, condition, data.branch.get(), - reportIfInconsistent = true + reportIfInconsistent = true, ) // add (not condition) to the data data.addBranch(notVar).noReturn() @@ -1852,7 +1850,7 @@ private fun SolverState.checkWhileExpression( private fun SolverState.checkLoopBody( body: Expression?, afterBody: List, - data: CheckData + data: CheckData, ): ContSeq { return checkExpressionConstraintsWithNewName("loop", body, data).flatMap { stateAfter -> // check the additional updates (used when describing "three-piece" for loops) @@ -1881,7 +1879,7 @@ private fun SolverState.checkLoopBody( private fun SolverState.checkTryExpression( associatedVarName: ObjectFormula, expression: TryExpression, - data: CheckData + data: CheckData, ): ContSeq = inScope(data) { ContSeq { @@ -1901,7 +1899,7 @@ private fun SolverState.checkTryExpression( doesAnyCatchMatch( stateAfter.returnInfo.exceptionType, expression.catchClauses, - data + data, ) ) ContSeq { abort() } // then there's no point in keep looking here @@ -1918,7 +1916,7 @@ private fun SolverState.checkTryExpression( checkExpressionConstraints( associatedVarName, it.catchBody, - data.addVarInfo(solver, paramName, smtName, param) + data.addVarInfo(solver, paramName, smtName, param), ) } } @@ -1943,7 +1941,7 @@ private fun SolverState.checkTryExpression( internal fun doesAnyCatchMatch( throwType: Type?, clauses: List, - data: CheckData + data: CheckData, ): Boolean = clauses.any { clause -> val catchType = clause.catchParameter?.type(data.context) @@ -1965,7 +1963,7 @@ internal fun Declaration.stableBody(): Expression? = private fun ContSeq.checkReturnInfo( r: (r: ExplicitReturn, s: StateAfter) -> A, - f: (StateAfter) -> ContSeq + f: (StateAfter) -> ContSeq, ): ContSeq = this.flatMap { stateAfter -> when (stateAfter.returnInfo) { diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Parameters.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Parameters.kt index e8e69634..f7282168 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Parameters.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/Parameters.kt @@ -15,7 +15,7 @@ data class ParamInfo( val smtName: String, val type: Type?, val element: Element?, - val thisFromConstructor: Boolean = false + val thisFromConstructor: Boolean = false, ) { companion object { public operator fun invoke( @@ -24,7 +24,7 @@ data class ParamInfo( smtName: String, type: Type?, element: Element?, - thisFromConstructor: Boolean = false + thisFromConstructor: Boolean = false, ): ParamInfo = ParamInfo(name, solver.escape(smtName), type, element, thisFromConstructor) } } @@ -34,7 +34,7 @@ internal fun SolverState.initialParameters( thisParam: ParamInfo?, valueParams: List, result: ParamInfo?, - context: ResolutionContext + context: ResolutionContext, ): List { val things = listOfNotNull(thisParam) + valueParams + listOfNotNull(result) return things.mapNotNull { param -> diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/CheckData.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/CheckData.kt index 12237e9f..36b62a75 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/CheckData.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/CheckData.kt @@ -10,7 +10,7 @@ data class CheckData( val context: ResolutionContext, val returnPoints: ReturnPoints, val varInfo: CurrentVarInfo, - val branch: CurrentBranch + val branch: CurrentBranch, ) { fun addReturnPoint(scope: String, variableName: ObjectFormula) = this.copy(returnPoints = returnPoints.addAndReplaceTopMost(scope, variableName)) @@ -23,7 +23,7 @@ data class CheckData( name: String, smtName: String, origin: Element, - invariant: BooleanFormula? = null + invariant: BooleanFormula? = null, ): CheckData = this.copy(varInfo = varInfo.add(solver, name, smtName, origin, invariant)) fun addVarInfos(vars: List): CheckData = this.copy(varInfo = varInfo.add(vars)) diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/Condition.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/Condition.kt index c03f843f..e98c0890 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/Condition.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/Condition.kt @@ -15,21 +15,21 @@ sealed class Condition( val condition: Element?, val isElse: Boolean, val body: Expression, - val whole: Element + val whole: Element, ) class SimpleCondition( val predicate: Expression?, isElse: Boolean, body: Expression, - whole: Element + whole: Element, ) : Condition(predicate, isElse, body, whole) class SubjectCondition( val check: WhenCondition?, isElse: Boolean, body: Expression, - whole: Element + whole: Element, ) : Condition(check, isElse, body, whole) // wrapping for missing else @@ -37,20 +37,29 @@ class MissingElseBlockExpression(val whole: Expression, val thenExpression: Expr BlockExpression { override val firstStatement: Expression? get() = null + override val statements: List get() = emptyList() + override val implicitReturnFromLast: Boolean get() = false + override val text: String get() = "" override fun impl(): Any = whole.impl() + override val psiOrParent: Element = this + override fun parents(): List = thenExpression.parents() override fun getResolvedCall(context: ResolutionContext): ResolvedCall? = null + override fun getVariableDescriptor(context: ResolutionContext): VariableDescriptor? = null + override fun location(): CompilerMessageSourceLocation? = whole.location() + override fun type(context: ResolutionContext): Type? = thenExpression.type(context) + override fun lastBlockStatementOrThis(): Expression = this } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/ControlFlowFn.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/ControlFlowFn.kt index b5ba4737..5c7a88b0 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/ControlFlowFn.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/ControlFlowFn.kt @@ -10,7 +10,7 @@ data class ControlFlowFn( val target: Expression?, val body: Expression, val argumentName: String, - val returnBehavior: ReturnBehavior + val returnBehavior: ReturnBehavior, ) { /** Describes whether functions return their argument or whatever is done in a block */ enum class ReturnBehavior { @@ -18,6 +18,6 @@ data class ControlFlowFn( RETURNS_ARGUMENT, /** Return whatever the enclosing block returns */ - RETURNS_BLOCK_RESULT + RETURNS_BLOCK_RESULT, } } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/CurrentVarInfo.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/CurrentVarInfo.kt index 6704c077..9705912e 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/CurrentVarInfo.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/CurrentVarInfo.kt @@ -13,7 +13,7 @@ data class CurrentVarInfo(private val varInfo: List) { name: String, smtName: String, origin: Element, - invariant: BooleanFormula? = null + invariant: BooleanFormula? = null, ): CurrentVarInfo = this.add(listOf(VarInfo(solver, name, smtName, origin, invariant))) fun add(vars: List): CurrentVarInfo = CurrentVarInfo(vars + varInfo) diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/LoopPlace.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/LoopPlace.kt index 21fe7136..c8c1e601 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/LoopPlace.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/LoopPlace.kt @@ -2,5 +2,5 @@ package arrow.meta.plugins.analysis.phases.analysis.solver.check.model enum class LoopPlace { INSIDE_LOOP, - AFTER_LOOP + AFTER_LOOP, } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/ReturnPoints.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/ReturnPoints.kt index aba73be0..df18c91c 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/ReturnPoints.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/ReturnPoints.kt @@ -7,7 +7,7 @@ import arrow.meta.plugins.analysis.smt.ObjectFormula /** Maps return points to the SMT variables representing that place. */ data class ReturnPoints( val topMostReturnPointVariableName: Pair, - val namedReturnPointVariableNames: Map + val namedReturnPointVariableNames: Map, ) { fun addAndReplaceTopMost(newScopeName: String, newVariableName: ObjectFormula) = @@ -19,7 +19,7 @@ data class ReturnPoints( private fun add(returnPoint: String, variableName: ObjectFormula) = ReturnPoints( topMostReturnPointVariableName, - namedReturnPointVariableNames + (returnPoint to variableName) + namedReturnPointVariableNames + (returnPoint to variableName), ) companion object { diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/VarInfo.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/VarInfo.kt index 2a3296c6..9fc792cd 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/VarInfo.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/check/model/VarInfo.kt @@ -15,7 +15,7 @@ private constructor( val name: String, val smtName: String, val origin: Element, - val invariant: BooleanFormula? = null + val invariant: BooleanFormula? = null, ) { companion object { public operator fun invoke( @@ -23,14 +23,14 @@ private constructor( name: String, smtName: String, origin: Element, - invariant: BooleanFormula? = null + invariant: BooleanFormula? = null, ): VarInfo = VarInfo(name, solver.escape(smtName), origin, invariant) public fun unsafeCreate( name: String, smtName: String, origin: Element, - invariant: BooleanFormula? = null + invariant: BooleanFormula? = null, ): VarInfo = VarInfo(name, smtName, origin, invariant) } } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/ExpressionToFormula.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/ExpressionToFormula.kt index 8a54665b..c48c5c30 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/ExpressionToFormula.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/ExpressionToFormula.kt @@ -61,7 +61,7 @@ internal fun SolverState.topLevelExpressionToFormula( ex: Expression?, context: ResolutionContext, parameters: List, - allowAnyReference: Boolean + allowAnyReference: Boolean, ): BooleanFormula? = expressionToFormula(ex, context, parameters, allowAnyReference)?.let { when (it) { @@ -76,7 +76,7 @@ private fun SolverState.expressionToFormula( ex: Expression?, context: ResolutionContext, parameters: List, - allowAnyReference: Boolean + allowAnyReference: Boolean, ): Formula? { val argCall = ex?.getResolvedCall(context) val recur = { v: Expression? -> expressionToFormula(v, context, parameters, allowAnyReference) } @@ -188,7 +188,7 @@ private fun Solver.wrap(formula: Formula, type: Type): Formula = private fun SolverState.fieldFormula( descriptor: CallableDescriptor, - args: List> + args: List>, ): ObjectFormula? = descriptor .takeIf { it.isField() } @@ -226,8 +226,7 @@ internal fun Element.isResultReference(bindingContext: ResolutionContext): Boole val params = lambdaArg?.functionLiteral?.valueParameters?.map { it.text }.orEmpty() + listOf("it") this.text in params.distinct() - } - ?: false + } ?: false internal fun Element.getPostOrInvariantParent(bindingContext: ResolutionContext): ResolvedCall? = this.parents() diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FindDescriptor.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FindDescriptor.kt index 5bed9412..59dfa8d3 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FindDescriptor.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FindDescriptor.kt @@ -36,7 +36,7 @@ internal fun SolverState.addConstraints( preConstraints: ArrayList, postConstraints: ArrayList, notLookConstraints: ArrayList, - bindingContext: ResolutionContext + bindingContext: ResolutionContext, ) { val lawSubject = findDescriptorFromRemoteLaw(descriptor, bindingContext) @@ -47,13 +47,13 @@ internal fun SolverState.addConstraints( val renamed = solver.renameConditions( DeclarationConstraints(descriptor, preConstraints, postConstraints, notLookConstraints), - lawSubject.withAliasUnwrapped + lawSubject.withAliasUnwrapped, ) callableConstraints.add( renamed.descriptor, ArrayList(renamed.pre), ArrayList(renamed.post), - ArrayList(renamed.doNotLookAtArgumentsWhen) + ArrayList(renamed.doNotLookAtArgumentsWhen), ) } callableConstraints.add(descriptor, preConstraints, postConstraints, notLookConstraints) @@ -62,7 +62,7 @@ internal fun SolverState.addConstraints( /** Finds the target of a particular law by looking up its [arrow.analysis.Subject] annotation */ private fun findDescriptorFromRemoteLaw( descriptor: DeclarationDescriptor, - context: ResolutionContext + context: ResolutionContext, ): DeclarationDescriptor? = descriptor.annotations().findAnnotation(FqName("arrow.analysis.Subject"))?.let { lawSubject -> val name = lawSubject.argumentValueAsString("fqName") @@ -81,7 +81,7 @@ private fun findDescriptorFromRemoteLaw( private fun ResolutionContext.obtainDeclaration( fqName: FqName, - compatibleWith: DeclarationDescriptor + compatibleWith: DeclarationDescriptor, ): DeclarationDescriptor? { val current = descriptorFor(fqName) // the type either strictly checks @@ -104,7 +104,7 @@ private fun ResolutionContext.obtainDeclaration( */ public fun SolverState.findDescriptorFromLocalLaw( descriptor: DeclarationDescriptor, - bindingContext: ResolutionContext + bindingContext: ResolutionContext, ): DeclarationDescriptor? { if (!descriptor.isALaw()) return null @@ -147,7 +147,7 @@ public fun SolverState.findDescriptorFromLocalLaw( private fun getReturnedExpressionWithoutPostcondition( function: Function, - bindingContext: ResolutionContext + bindingContext: ResolutionContext, ): ResolvedCall? { val lastElementWithoutReturn = when (val lastElement = function.body()?.lastBlockStatementOrThis()) { @@ -167,8 +167,7 @@ private fun getReturnedExpressionWithoutPostcondition( } } else -> null - } - ?: lastElementWithoutReturn + } ?: lastElementWithoutReturn return veryLast?.getResolvedCall(bindingContext) } @@ -181,7 +180,7 @@ private fun MutableMap>.add( descriptor: DeclarationDescriptor, pre: ArrayList, post: ArrayList, - doNotLookAtArgumentsWhen: ArrayList + doNotLookAtArgumentsWhen: ArrayList, ) { val fqName = descriptor.fqNameSafe // create a new one if not existent @@ -197,7 +196,7 @@ private fun MutableMap>.add( descriptor, previous.pre + pre, previous.post + post, - previous.doNotLookAtArgumentsWhen + doNotLookAtArgumentsWhen + previous.doNotLookAtArgumentsWhen + doNotLookAtArgumentsWhen, ) } } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromAnnotations.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromAnnotations.kt index 3015220e..96ef7ee3 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromAnnotations.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromAnnotations.kt @@ -21,7 +21,7 @@ import org.sosy_lab.java_smt.api.BooleanFormula public fun SolverState.collectConstraintsFromAnnotations( localDeclarations: List, module: ModuleDescriptor, - bindingTrace: ResolutionContext + bindingTrace: ResolutionContext, ): Pair> { // check local declarations for @Laws collectFromLocalDeclarations(localDeclarations, bindingTrace) @@ -44,7 +44,7 @@ public fun SolverState.collectConstraintsFromAnnotations( private fun SolverState.collectFromLocalDeclarations( localDeclarations: List, - bindingTrace: ResolutionContext + bindingTrace: ResolutionContext, ) { localDeclarations .flatMap { it.gather { it.hasInterestingAnnotation } } @@ -53,7 +53,7 @@ private fun SolverState.collectFromLocalDeclarations( private fun SolverState.collectFromClasspath( module: ModuleDescriptor, - bindingTrace: ResolutionContext + bindingTrace: ResolutionContext, ) { val collectEntireClasspath = System.getProperty("ARROW_ANALYSIS_COLLECT_ENTIRE_CLASSPATH", "false").toBooleanStrictOrNull() @@ -66,7 +66,7 @@ private fun SolverState.collectFromClasspath( module .gather( initialPackages = listOf(FqName("arrow.analysis.hints")), - addSubPackages = false + addSubPackages = false, ) { it.hasPackageWithLawsAnnotation } @@ -81,7 +81,7 @@ private fun SolverState.collectFromClasspath( internal fun SolverState.addConstraintsFromAnnotations( descriptor: DeclarationDescriptor, - bindingContext: ResolutionContext + bindingContext: ResolutionContext, ) { val constraints = descriptor.annotations().iterable().mapNotNull { ann -> @@ -109,7 +109,7 @@ internal fun SolverState.addConstraintsFromAnnotations( private fun SolverState.parseFormula( element: String, annotation: AnnotationDescriptor, - descriptor: DeclarationDescriptor + descriptor: DeclarationDescriptor, ): Pair> { val dependencies = annotation.argumentValueAsArrayOfString("dependencies") val formulae = annotation.argumentValueAsArrayOfString("formulae") @@ -124,7 +124,7 @@ private fun SolverState.parseFormula( internal fun SolverState.parseFormula( descriptor: DeclarationDescriptor, formula: String, - dependencies: List + dependencies: List, ): BooleanFormula { val VALUE_TYPE = "Int" val FIELD_TYPE = "Int" @@ -134,8 +134,7 @@ internal fun SolverState.parseFormula( function.valueParameters.joinToString(separator = "\n") { param -> "(declare-fun ${param.name} () $VALUE_TYPE)" } - } - ?: "" + } ?: "" // build the dependencies val deps = dependencies.joinToString(separator = "\n") { "(declare-fun $it () $FIELD_TYPE)" } // build the rest of the environment diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromDSL.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromDSL.kt index de1459da..4eca9f09 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromDSL.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/FromDSL.kt @@ -41,7 +41,7 @@ import org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor public fun Declaration.collectConstraintsFromDSL( solverState: SolverState, context: ResolutionContext, - descriptor: DeclarationDescriptor + descriptor: DeclarationDescriptor, ) { if ( this is ClassOrObject && @@ -55,7 +55,7 @@ public fun Declaration.collectConstraintsFromDSL( solverState, context, getPrimaryConstructorParameterList()?.parameters.orEmpty(), - this + this, ) if (preConstraints.isNotEmpty() || postConstraints.isNotEmpty()) { solverState.addConstraints( @@ -63,7 +63,7 @@ public fun Declaration.collectConstraintsFromDSL( preConstraints, postConstraints, arrayListOf(), - context + context, ) } } else { @@ -73,7 +73,7 @@ public fun Declaration.collectConstraintsFromDSL( solverState, context, valueParameters, - getContainingClassOrObject() + getContainingClassOrObject(), ) is DeclarationWithBody -> constraintsFromFunctionLike(solverState, context, valueParameters.filterNotNull()) @@ -91,7 +91,7 @@ public fun Declaration.collectConstraintsFromDSL( preConstraints, postConstraints, notLookConstraints, - context + context, ) } } @@ -106,7 +106,7 @@ public fun Declaration.collectConstraintsFromDSL( private fun Declaration.constraintsFromGenericDeclaration( solverState: SolverState, context: ResolutionContext, - parameters: List + parameters: List, ): List> = context.run { constraintsDSLElements().mapNotNull { it.elementToConstraint(solverState, context, parameters) } @@ -116,7 +116,7 @@ private fun Declaration.constraintsFromGenericDeclaration( private fun Declaration.constraintsFromFunctionLike( solverState: SolverState, context: ResolutionContext, - parameters: List + parameters: List, ): Triple, ArrayList, ArrayList> { val preConstraints = arrayListOf() val postConstraints = arrayListOf() @@ -140,7 +140,7 @@ private fun > Constructor?.constraintsFromConstructor( solverState: SolverState, context: ResolutionContext, parameters: List, - containingClassOrObject: ClassOrObject + containingClassOrObject: ClassOrObject, ): Triple, ArrayList, ArrayList> { val preConstraints = arrayListOf() val postConstraints = arrayListOf() @@ -155,7 +155,7 @@ private fun > Constructor?.constraintsFromConstructor( parameters, !isRequireOrAssert, call, - formula.formula + formula.formula, ) ?.let { preConstraints.add(NamedConstraint(formula.msg, it)) } } @@ -176,7 +176,7 @@ private fun rewritePrecondition( parameters: List, raiseErrorWhenUnexpected: Boolean, call: ResolvedCall, - formula: BooleanFormula + formula: BooleanFormula, ): BooleanFormula? { val mgr = solverState.solver.formulaManager var errorSignaled = false @@ -187,7 +187,7 @@ private fun rewritePrecondition( override fun visitFunction( f: Formula?, args: MutableList?, - fn: FunctionDeclaration<*>? + fn: FunctionDeclaration<*>?, ): Formula = if (fn?.name == Solver.FIELD_FUNCTION_NAME) { val fieldName = args?.getOrNull(0)?.let { mgr.extractSingleVariable(it) } @@ -212,7 +212,7 @@ private fun rewritePrecondition( context.handleError( ErrorIds.Parsing.UnexpectedFieldInitBlock, call.callElement, - msg + msg, ) } super.visitFunction(f, args, fn) @@ -223,7 +223,7 @@ private fun rewritePrecondition( } else { super.visitFunction(f, args, fn) } - } + }, ) return result.takeIf { !errorSignaled } } @@ -231,7 +231,7 @@ private fun rewritePrecondition( /** Turn references to 'this' into references to '$result' */ private fun rewritePostcondition( solverState: SolverState, - formula: BooleanFormula + formula: BooleanFormula, ): BooleanFormula { val mgr = solverState.solver.formulaManager return mgr.transformRecursively( @@ -243,7 +243,7 @@ private fun rewritePostcondition( } else { super.visitFreeVariable(f, name) } - } + }, ) } @@ -251,7 +251,7 @@ private fun rewritePostcondition( private fun Element.elementToConstraint( solverState: SolverState, context: ResolutionContext, - parameters: List + parameters: List, ): Pair? { val call = getResolvedCall(context) val kind = call?.specialKind diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/model/DeclarationConstraints.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/model/DeclarationConstraints.kt index b0aad35b..9556169b 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/model/DeclarationConstraints.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/collect/model/DeclarationConstraints.kt @@ -6,5 +6,5 @@ data class DeclarationConstraints( val descriptor: DeclarationDescriptor, val pre: List, val post: List, - val doNotLookAtArgumentsWhen: List + val doNotLookAtArgumentsWhen: List, ) diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds.kt index f9501eea..36f10e92 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds.kt @@ -4,7 +4,7 @@ enum class SeverityLevel { Error, Warning, Info, - Unsupported + Unsupported, } sealed interface ErrorIds { @@ -12,9 +12,11 @@ sealed interface ErrorIds { val name: String val id: String get() = name + val shortDescription: String val fullDescription: String? get() = null + val level: SeverityLevel get() = SeverityLevel.Error @@ -135,7 +137,7 @@ sealed interface ErrorIds { ``` """ .trimIndent() - } + }, } enum class Inconsistency : ErrorIds { @@ -261,7 +263,7 @@ sealed interface ErrorIds { (Liskov Substitution Principle). """ .trimIndent() - } + }, } enum class Exception : ErrorIds { diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorMessages.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorMessages.kt index 7ee25be0..e6ca9224 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorMessages.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorMessages.kt @@ -118,7 +118,7 @@ object ErrorMessages { callPreCondition: NamedConstraint, resolvedCall: ResolvedCall, branch: Branch, - model: Model + model: Model, ): String = """|pre-condition `${callPreCondition.msg}` is not satisfied in `${resolvedCall.callElement.text}` | -> unsatisfiable constraint: `${callPreCondition.formula.dumpKotlinLike()}` @@ -145,7 +145,7 @@ object ErrorMessages { internal fun KotlinPrinter.unsatBodyPost( declaration: Declaration, postCondition: NamedConstraint, - branch: Branch + branch: Branch, ): String = """|declaration `${declaration.name}` fails to satisfy the post-condition: ${postCondition.formula.dumpKotlinLike()} | -> ${branch(branch)} @@ -170,7 +170,7 @@ object ErrorMessages { expression: Element, constraint: NamedConstraint, branch: Branch, - model: Model + model: Model, ): String = """|invariants are not satisfied in `${expression.text}` | -> unsatisfiable constraint: `${constraint.formula.dumpKotlinLike()}` @@ -213,7 +213,7 @@ object ErrorMessages { */ internal fun KotlinPrinter.inconsistentBodyPre( declaration: Declaration, - unsatCore: List + unsatCore: List, ): String = "${declaration.name} has inconsistent pre-conditions: ${unsatCore.joinToString { it.dumpKotlinLike() }}" @@ -231,7 +231,7 @@ object ErrorMessages { */ internal fun KotlinPrinter.inconsistentDefaultValues( declaration: Declaration, - unsatCore: List + unsatCore: List, ): String = "${declaration.name} has inconsistent default values: ${unsatCore.dumpKotlinLike()}" /** @@ -254,7 +254,7 @@ object ErrorMessages { */ internal fun KotlinPrinter.inconsistentConditions( unsatCore: List, - branch: Branch + branch: Branch, ): String = """|unreachable code due to conflicting conditions: ${unsatCore.dumpKotlinLike()} | -> ${branch(branch)} @@ -267,7 +267,7 @@ object ErrorMessages { */ internal fun KotlinPrinter.inconsistentCallPost( unsatCore: List, - branch: Branch + branch: Branch, ): String = """|unreachable code due to post-conditions: ${unsatCore.dumpKotlinLike()} | -> ${branch(branch)} @@ -289,7 +289,7 @@ object ErrorMessages { */ internal fun KotlinPrinter.inconsistentInvariants( it: List, - branch: Branch + branch: Branch, ): String = """|invariants are inconsistent: ${it.dumpKotlinLike()} | -> ${branch(branch)} @@ -333,11 +333,9 @@ object ErrorMessages { val paramPsi = param.element() val location = paramPsi?.let { paramPsi.location() } "`${el.text}` bound to param `${param.name}` in `${param.containingDeclaration?.fqNameSafe}` ${location?.link() ?: ""}" - } - ?: "" + } ?: "" } - ?.takeIf { it.isNotEmpty() } - ?: "" + ?.takeIf { it.isNotEmpty() } ?: "" } internal fun KotlinPrinter.branch(conditions: Branch): String = diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/search/ConstraintSearch.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/search/ConstraintSearch.kt index f2c01ec9..fcae2925 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/search/ConstraintSearch.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/search/ConstraintSearch.kt @@ -86,13 +86,13 @@ internal fun intersectNameds(one: List, other: List = typeInvariants(type, solver.makeObjectVariable(resultName), context) internal fun SolverState.typeInvariants( type: Type, result: ObjectFormula, - context: ResolutionContext + context: ResolutionContext, ): List { // invariants from the type val invariants = @@ -103,11 +103,10 @@ internal fun SolverState.typeInvariants( constraints.map { NamedConstraint( "${it.msg} (invariant from $type)", - solver.substituteObjectVariables(it.formula, mapOf(RESULT_VAR_NAME to result)) + solver.substituteObjectVariables(it.formula, mapOf(RESULT_VAR_NAME to result)), ) } - } - ?: emptyList() + } ?: emptyList() // invariants from property code val fieldEqs = fieldEqualitiesInvariants(type, result, context) // invariants about nullability @@ -123,7 +122,7 @@ internal fun SolverState.typeInvariants( internal fun SolverState.fieldEqualitiesInvariants( type: Type, resultName: String, - context: ResolutionContext + context: ResolutionContext, ): List = fieldEqualitiesInvariants(type, solver.makeObjectVariable(resultName), context) @@ -134,7 +133,7 @@ internal fun SolverState.fieldEqualitiesInvariants( internal fun SolverState.fieldEqualitiesInvariants( type: Type, result: ObjectFormula, - context: ResolutionContext + context: ResolutionContext, ): List = (type.descriptor?.element() as? DeclarationContainer).singleFieldGroups(context).flatMap { set -> when (set.size) { @@ -146,7 +145,7 @@ internal fun SolverState.fieldEqualitiesInvariants( rest.map { NamedConstraint( "${it.fqNameSafe.asField} is ${first.fqNameSafe.asField}", - solver.objects { equal(field(it, result), field(first, result)) } + solver.objects { equal(field(it, result), field(first, result)) }, ) } } @@ -174,7 +173,7 @@ internal fun SolverState.getOverriddenConstraintsFor( descriptor, overriddenConstraints.flatMap { it.pre }, overriddenConstraints.flatMap { it.post }, - overriddenConstraints.flatMap { it.doNotLookAtArgumentsWhen } + overriddenConstraints.flatMap { it.doNotLookAtArgumentsWhen }, ) } @@ -232,21 +231,21 @@ internal fun SolverState.primitiveConstraints( solver.booleans { equivalence( solver.makeBooleanObjectVariable(RESULT_VAR_NAME), - formula as BooleanFormula + formula as BooleanFormula, ) } PrimitiveType.INTEGRAL -> solver.ints { equal( solver.makeIntegerObjectVariable(RESULT_VAR_NAME), - formula as NumeralFormula.IntegerFormula + formula as NumeralFormula.IntegerFormula, ) } PrimitiveType.RATIONAL -> solver.rationals { equal( solver.makeIntegerObjectVariable(RESULT_VAR_NAME), - formula as NumeralFormula.RationalFormula + formula as NumeralFormula.RationalFormula, ) } else -> solver.objects { equal(solver.resultVariable, formula as ObjectFormula) } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverInteraction.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverInteraction.kt index c954a9fa..4432b385 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverInteraction.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverInteraction.kt @@ -45,7 +45,7 @@ internal fun SolverState.checkInconsistency( internal fun SolverState.addAndCheckConsistency( constraints: Iterable, context: ResolutionContext, - message: (unsatCore: List) -> Unit + message: (unsatCore: List) -> Unit, ): Boolean { constraints.forEach { addConstraint(it, context) } additionalFieldConstraints(constraints, context).forEach { addConstraint(it, context) } @@ -55,14 +55,14 @@ internal fun SolverState.addAndCheckConsistency( internal fun SolverState.checkImplicationOf( constraint: NamedConstraint, context: ResolutionContext, - message: (model: Model) -> Unit + message: (model: Model) -> Unit, ): Boolean = checkImplicationOf(constraint, true, context, message) internal fun SolverState.checkImplicationOf( constraint: NamedConstraint, addFieldConstraints: Boolean, context: ResolutionContext, - message: (model: Model) -> Unit + message: (model: Model) -> Unit, ): Boolean = bracket { solver.booleans { addConstraint(NamedConstraint("!(${constraint.msg})", not(constraint.formula)), context) @@ -79,7 +79,7 @@ internal fun SolverState.checkImplicationOf( internal fun SolverState.additionalFieldConstraints( formulae: Iterable, - context: ResolutionContext + context: ResolutionContext, ): Set = solver.formulaManager .fieldNames(formulae.map { it.formula }) @@ -98,8 +98,8 @@ internal fun SolverState.additionalFieldConstraints( constraints.post[0].msg, solver.substituteVariable( constraints.post[0].formula, - mapOf(RESULT_VAR_NAME to field(descriptor, appliedTo), "this" to appliedTo) - ) + mapOf(RESULT_VAR_NAME to field(descriptor, appliedTo), "this" to appliedTo), + ), ) ) } else { @@ -117,7 +117,7 @@ internal fun SolverState.singleConstraintsFromFqName(name: FqName): DeclarationC internal fun SolverState.checkDefaultValueInconsistency( context: ResolutionContext, - declaration: Declaration + declaration: Declaration, ): Boolean = solver.run { checkInconsistency { unsatCore -> @@ -137,7 +137,7 @@ internal fun SolverState.checkDefaultValueInconsistency( internal fun SolverState.checkPreconditionsInconsistencies( constraints: DeclarationConstraints?, context: ResolutionContext, - declaration: Declaration + declaration: Declaration, ): Boolean = solver.run { constraints?.pre?.let { @@ -145,8 +145,7 @@ internal fun SolverState.checkPreconditionsInconsistencies( val msg = inconsistentBodyPre(declaration, unsatCore) context.handleError(ErrorIds.Inconsistency.InconsistentBodyPre, declaration, msg) } - } - ?: false // if there are no preconditions, they are consistent + } ?: false // if there are no preconditions, they are consistent } /** @@ -158,7 +157,7 @@ internal fun SolverState.checkPostConditionsImplication( isConstructor: Boolean, context: ResolutionContext, declaration: Declaration, - branch: Branch + branch: Branch, ) { solver.run { constraints?.post?.forEach { postCondition -> @@ -176,7 +175,7 @@ internal fun SolverState.checkCallPreConditionsImplication( context: ResolutionContext, expression: Expression, resolvedCall: ResolvedCall, - branch: Branch + branch: Branch, ) = solver.run { callConstraints?.pre?.forEach { callPreCondition -> @@ -192,7 +191,7 @@ internal fun SolverState.checkCallPostConditionsInconsistencies( callConstraints: DeclarationConstraints?, context: ResolutionContext, expression: Expression, - branch: Branch + branch: Branch, ): Boolean = solver.run { callConstraints?.post?.let { @@ -200,8 +199,7 @@ internal fun SolverState.checkCallPostConditionsInconsistencies( val msg = inconsistentCallPost(unsatCore, branch) context.handleError(ErrorIds.Inconsistency.InconsistentCallPost, expression, msg) } - } - ?: false + } ?: false } /** Add the [formulae] to the set and checks that it remains consistent */ @@ -210,7 +208,7 @@ internal fun SolverState.checkConditionsInconsistencies( context: ResolutionContext, expression: Element, branch: Branch, - reportIfInconsistent: Boolean + reportIfInconsistent: Boolean, ): Boolean = solver.run { addAndCheckConsistency(formulae, context) { unsatCore -> @@ -225,7 +223,7 @@ internal fun SolverState.checkInvariantConsistency( constraint: NamedConstraint, context: ResolutionContext, expression: Element, - branch: Branch + branch: Branch, ): Boolean = solver.run { addAndCheckConsistency(listOf(constraint), context) { @@ -238,7 +236,7 @@ internal fun SolverState.checkInvariant( constraint: NamedConstraint, context: ResolutionContext, expression: Element, - branch: Branch + branch: Branch, ): Boolean = solver.run { checkImplicationOf(constraint, context) { model -> @@ -250,7 +248,7 @@ internal fun SolverState.checkInvariant( internal fun SolverState.checkLiskovWeakerPrecondition( constraint: NamedConstraint, context: ResolutionContext, - expression: Element + expression: Element, ): Boolean = solver.run { checkImplicationOf(constraint, context) { @@ -262,7 +260,7 @@ internal fun SolverState.checkLiskovWeakerPrecondition( internal fun SolverState.checkLiskovStrongerPostcondition( constraint: NamedConstraint, context: ResolutionContext, - expression: Element + expression: Element, ): Boolean = solver.run { checkImplicationOf(constraint, context) { diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverState.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverState.kt index e6c3dc47..56be1c05 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverState.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/state/SolverState.kt @@ -34,7 +34,7 @@ data class SolverState( val prover: ProverEnvironment = solver.newProverEnvironment( SolverContext.ProverOptions.GENERATE_MODELS, - SolverContext.ProverOptions.GENERATE_UNSAT_CORE + SolverContext.ProverOptions.GENERATE_UNSAT_CORE, ), val callableConstraints: MutableMap> = mutableMapOf(), val solverTrace: MutableList = mutableListOf(), @@ -97,7 +97,7 @@ data class SolverState( context: ResolutionContext, prefix: String, element: Element?, - reference: Pair? + reference: Pair?, ): String { val type = (element as? Expression)?.type(context) val info = element?.let { ReferencedElement(it, reference, type) } diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/sarif/ReportedError.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/sarif/ReportedError.kt index fab90dcf..b05bf6c1 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/sarif/ReportedError.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/sarif/ReportedError.kt @@ -8,5 +8,5 @@ data class ReportedError( val errorsId: ErrorIds, val element: Element, val msg: String, - val references: List + val references: List, ) diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/sarif/SarifReporter.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/sarif/SarifReporter.kt index 685b3b23..4f7a7345 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/sarif/SarifReporter.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/sarif/SarifReporter.kt @@ -23,7 +23,7 @@ import kotlin.io.path.Path fun sarifFileContent( baseDir: String, analysisVersion: String, - errors: List + errors: List, ): String { val sarifSchema210 = SarifSchema210( @@ -49,12 +49,12 @@ fun sarifFileContent( .map(ErrorIds::toDescriptor), organization = "arrow-kt", semanticVersion = analysisVersion, - version = analysisVersion + version = analysisVersion, ) ), - results = toResults(baseDir, errors) + results = toResults(baseDir, errors), ) - ) + ), ) return SarifSerializer.toJson(sarifSchema210) } @@ -69,7 +69,7 @@ private fun ErrorIds.toDescriptor(): ReportingDescriptor = null -> MultiformatMessageString(text = shortDescription) else -> MultiformatMessageString(markdown = d, text = d) }, - helpURI = "https://arrow-kt.io/docs/meta/analysis/${id}.html" + helpURI = "https://arrow-kt.io/docs/meta/analysis/${id}.html", ) fun toResults(baseDir: String, errors: List): List = @@ -99,7 +99,7 @@ private fun ReportedError.toResult(baseDir: String) = .mapNotNull { it?.toLocation(baseDir) } .toSet() .toList(), - message = Message(text = msg) + message = Message(text = msg), ) private fun rel(baseDir: String, path: String): String { @@ -111,11 +111,7 @@ private fun CompilerMessageSourceLocation.toLocation(baseDir: String): Location Location( physicalLocation = PhysicalLocation( - region = - Region( - startLine = line.toLong(), - startColumn = column.toLong(), - ), - artifactLocation = ArtifactLocation(uri = rel(baseDir, path)) + region = Region(startLine = line.toLong(), startColumn = column.toLong()), + artifactLocation = ArtifactLocation(uri = rel(baseDir, path)), ) ) diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/FormulaExtensions.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/FormulaExtensions.kt index d583f467..3c050e31 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/FormulaExtensions.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/FormulaExtensions.kt @@ -22,7 +22,7 @@ fun Solver.substituteVariable(formula: T, mapping: Map Solver.renameObjectVariables( formula: T, - mapping: Map + mapping: Map, ): T = try { formulae { @@ -36,7 +36,7 @@ internal fun Solver.renameObjectVariables( internal fun Solver.substituteObjectVariables( formula: T, - mapping: Map + mapping: Map, ): T = try { formulae { @@ -49,27 +49,27 @@ internal fun Solver.substituteObjectVariables( fun Solver.renameDeclarationConstraints( decl: DeclarationConstraints, - mapping: Map + mapping: Map, ): DeclarationConstraints { fun go(c: NamedConstraint) = NamedConstraint(c.msg, renameObjectVariables(c.formula, mapping)) return DeclarationConstraints( decl.descriptor, decl.pre.map(::go), decl.post.map(::go), - decl.doNotLookAtArgumentsWhen.map(::go) + decl.doNotLookAtArgumentsWhen.map(::go), ) } fun Solver.substituteDeclarationConstraints( decl: DeclarationConstraints, - mapping: Map + mapping: Map, ): DeclarationConstraints { fun go(c: NamedConstraint) = NamedConstraint(c.msg, substituteObjectVariables(c.formula, mapping)) return DeclarationConstraints( decl.descriptor, decl.pre.map(::go), decl.post.map(::go), - decl.doNotLookAtArgumentsWhen.map(::go) + decl.doNotLookAtArgumentsWhen.map(::go), ) } @@ -78,10 +78,11 @@ fun FormulaManager.fieldNames(f: Formula): Set> { val visitor = object : DefaultFormulaVisitor() { override fun visitDefault(f: Formula?): TraversalProcess = TraversalProcess.CONTINUE + override fun visitFunction( f: Formula?, args: MutableList?, - fn: FunctionDeclaration<*>? + fn: FunctionDeclaration<*>?, ): TraversalProcess { val secondArg = args?.getOrNull(1) as? ObjectFormula if (fn?.name == Solver.FIELD_FUNCTION_NAME && secondArg != null) { @@ -103,6 +104,7 @@ fun FormulaManager.isSingleVariable(f: Formula): Boolean { val visitor = object : DefaultFormulaVisitor() { override fun visitDefault(f: Formula?): Boolean = false + override fun visitFreeVariable(f: Formula?, name: String?): Boolean = true } return visit(f, visitor) @@ -112,10 +114,11 @@ fun Solver.isFieldCall(f: Formula): Boolean { val visitor = object : DefaultFormulaVisitor() { override fun visitDefault(f: Formula?): Boolean = false + override fun visitFunction( f: Formula?, args: MutableList?, - functionDeclaration: FunctionDeclaration<*>? + functionDeclaration: FunctionDeclaration<*>?, ): Boolean = functionDeclaration?.name == Solver.FIELD_FUNCTION_NAME } return visit(f, visitor) @@ -135,7 +138,7 @@ fun Solver.substituteWithFix(pF: T, pFromToMapping: Map, - functionDeclaration: FunctionDeclaration<*> + functionDeclaration: FunctionDeclaration<*>, ): Formula = pFromToMapping[f] ?: makeApplicationSafe(functionDeclaration, newArgs) private fun replace(f: Formula): Formula = pFromToMapping[f] ?: f @@ -151,11 +154,11 @@ fun Solver.substituteWithFix(pF: T, pFromToMapping: Map makeApplication(newFn, listOf(acc, f)) } } - } + }, ) diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/Solver.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/Solver.kt index 2c4fae68..6f1ede35 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/Solver.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/Solver.kt @@ -130,7 +130,7 @@ class Solver(context: SolverContext, nameProvider: NameProvider) : BOOL_VALUE_NAME, DECIMAL_VALUE_NAME, FIELD_FUNCTION_NAME, - IS_NULL_FUNCTION_NAME + IS_NULL_FUNCTION_NAME, ) override fun escape(name: String): String = @@ -144,7 +144,7 @@ class Solver(context: SolverContext, nameProvider: NameProvider) : operator fun invoke(nameProvider: NameProvider): Solver = Solver( SolverContextFactory.createSolverContext(SolverContextFactory.Solvers.SMTINTERPOL), - nameProvider + nameProvider, ) val INT_VALUE_NAME = "int" diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FieldProvider.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FieldProvider.kt index a12c780f..a26c92d5 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FieldProvider.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FieldProvider.kt @@ -10,7 +10,7 @@ class FieldProvider( private val solver: Solver, private val prover: ProverEnvironment, internal val basicFields: MutableMap, - private var current: Long + private var current: Long, ) { fun introduce(descriptor: DeclarationDescriptor): Long { diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FormulaToKotlin.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FormulaToKotlin.kt index 65fa4907..bfcdf79b 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FormulaToKotlin.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/FormulaToKotlin.kt @@ -9,7 +9,9 @@ import org.sosy_lab.java_smt.api.visitors.DefaultFormulaVisitor interface KotlinPrinter { fun Formula.dumpKotlinLike(): String + fun Formula.dumpKotlinLikeOrRemove(): String? + fun mirroredElement(name: String): ReferencedElement? fun List.dumpKotlinLike(): String = @@ -18,7 +20,7 @@ interface KotlinPrinter { internal class DefaultKotlinPrinter( private val fmgr: FormulaManager, - private val nameProvider: NameProvider + private val nameProvider: NameProvider, ) : KotlinPrinter { override fun mirroredElement(name: String): ReferencedElement? = @@ -28,7 +30,7 @@ internal class DefaultKotlinPrinter( val str = StringBuilder() fmgr.visit( this, - KotlinPrintVisitor(fmgr, str, nameProvider, parensContext = false, negatedContext = false) + KotlinPrintVisitor(fmgr, str, nameProvider, parensContext = false, negatedContext = false), ) return str.toString() } @@ -40,7 +42,7 @@ internal class DefaultKotlinPrinter( private val out: StringBuilder, private val nameProvider: NameProvider, private val parensContext: Boolean, - private val negatedContext: Boolean + private val negatedContext: Boolean, ) : DefaultFormulaVisitor() { override fun visitDefault(pF: Formula): Void? { @@ -62,7 +64,7 @@ internal class DefaultKotlinPrinter( Binary, Hidden, Field, - Unsupported + Unsupported, } private fun FunctionDeclaration<*>.toKotlin(): Triple = @@ -94,7 +96,7 @@ internal class DefaultKotlinPrinter( override fun visitFunction( pF: Formula, pArgs: List, - pFunctionDeclaration: FunctionDeclaration<*> + pFunctionDeclaration: FunctionDeclaration<*>, ): Void? { val (render, name, negatedName) = pFunctionDeclaration.toKotlin() when (render) { @@ -109,12 +111,12 @@ internal class DefaultKotlinPrinter( val leftStringBuilder = StringBuilder() fmgr.visit( pArgs[0], - this.copy(out = leftStringBuilder, parensContext = true, negatedContext = false) + this.copy(out = leftStringBuilder, parensContext = true, negatedContext = false), ) val rightStringBuilder = StringBuilder() fmgr.visit( pArgs[1], - this.copy(out = rightStringBuilder, parensContext = true, negatedContext = false) + this.copy(out = rightStringBuilder, parensContext = true, negatedContext = false), ) if (leftStringBuilder.toString() == rightStringBuilder.toString()) { diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/NameProvider.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/NameProvider.kt index 3bf55620..1a13b8ae 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/NameProvider.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/smt/utils/NameProvider.kt @@ -10,7 +10,7 @@ import java.util.concurrent.atomic.AtomicReference data class ReferencedElement( val element: Element, val reference: Pair?, - val type: Type? + val type: Type?, ) class NameProvider { diff --git a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/types/PrimitiveType.kt b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/types/PrimitiveType.kt index 3881f2d3..bc1b2d6e 100644 --- a/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/types/PrimitiveType.kt +++ b/analysis/common/src/main/kotlin/arrow/meta/plugins/analysis/types/PrimitiveType.kt @@ -8,7 +8,7 @@ enum class PrimitiveType { INTEGRAL, RATIONAL, CHAR, - STRING + STRING, } fun Type.unwrapIfNullable(): Type = diff --git a/analysis/example/build.gradle.kts b/analysis/example/build.gradle.kts index 4d9b402e..631c5fe8 100644 --- a/analysis/example/build.gradle.kts +++ b/analysis/example/build.gradle.kts @@ -19,18 +19,19 @@ kotlin { commonMain { dependencies { implementation(libs.kotlin.stdlibCommon) + implementation(kotlin("stdlib-common")) api(projects.arrowAnalysisLaws) api(projects.arrowAnalysisTypes) } } - named("jvmMain") { + jvmMain { dependencies { implementation(libs.kotlin.stdlibJDK8) } } - named("jsMain") { + jsMain { dependencies { implementation(libs.kotlin.stdlibJS) } @@ -39,17 +40,18 @@ kotlin { } dependencies { - kotlinCompilerClasspath(projects.arrowAnalysisKotlinPlugin) + kotlinCompilerPluginClasspath(projects.arrowAnalysisKotlinPlugin) + kotlinCompilerPluginClasspath(projects.arrowAnalysisLaws) } tasks.compileKotlinJvm { - kotlinOptions { - dependsOn(":arrow-analysis-laws:jar") - freeCompilerArgs = listOf( + compilerOptions { + //dependsOn(":arrow-analysis-laws:jar") + freeCompilerArgs.set(listOf( "-Xplugin=$rootDir/analysis/kotlin-plugin/build/libs/arrow-analysis-kotlin-plugin-$version.jar", "-P", "plugin:arrow.meta.plugin.compiler.analysis:generatedSrcOutputDir=$buildDir/generated/meta", "-P", "plugin:arrow.meta.plugin.compiler.analysis:baseDir=${project.rootProject.rootDir.path}" - ) + )) } } diff --git a/analysis/example/src/commonMain/kotlin/arrow/analysis/BadExample.kt b/analysis/example/src/commonMain/kotlin/arrow/analysis/BadExample.kt index c575c0e6..3232cf6d 100644 --- a/analysis/example/src/commonMain/kotlin/arrow/analysis/BadExample.kt +++ b/analysis/example/src/commonMain/kotlin/arrow/analysis/BadExample.kt @@ -8,6 +8,7 @@ fun bar(x: Int): Int { pre(x > 0) { "x positive" } return 1 / x } + // val other: Int = emptyList().get(1) fun increment(x: Int): Int { diff --git a/analysis/java-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisJavaGradlePlugin.kt b/analysis/java-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisJavaGradlePlugin.kt index a4d157ca..033dc4d5 100644 --- a/analysis/java-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisJavaGradlePlugin.kt +++ b/analysis/java-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisJavaGradlePlugin.kt @@ -25,7 +25,7 @@ public class AnalysisJavaGradlePlugin : Plugin { task.options.compilerArgs.addAll( listOf( "-parameters", // IMPORTANT! otherwise we have no parameter names - "-Xplugin:ArrowAnalysisJavaPlugin generatedSrcOutputDir=${p.buildDir} baseDir=${p.rootProject.rootDir.path}" + "-Xplugin:ArrowAnalysisJavaPlugin generatedSrcOutputDir=${p.buildDir} baseDir=${p.rootProject.rootDir.path}", ) ) } diff --git a/analysis/java-plugin/build.gradle.kts b/analysis/java-plugin/build.gradle.kts index 41e8bcfa..9dd881cd 100644 --- a/analysis/java-plugin/build.gradle.kts +++ b/analysis/java-plugin/build.gradle.kts @@ -1,5 +1,8 @@ @file:Suppress("DSL_SCOPE_VIOLATION") +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion + + plugins { id(libs.plugins.kotlin.jvm.get().pluginId) alias(libs.plugins.arrowGradleConfig.publish) @@ -8,6 +11,9 @@ plugins { } kotlin { + compilerOptions { + languageVersion.set(KotlinVersion.KOTLIN_1_9) + } explicitApi = null jvmToolchain { (this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(11)) diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisContext.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisContext.kt index 5570d229..ba9e579e 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisContext.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisContext.kt @@ -20,7 +20,7 @@ import javax.lang.model.util.Types public open class AnalysisContextWithoutResolver( public val context: Context, public val types: Types, - public val elements: Elements + public val elements: Elements, ) { public val logger: Log = Log.instance(context) public val messages: JavacMessages = @@ -47,7 +47,7 @@ public class AnalysisContext( types: Types, elements: Elements, public val unit: CompilationUnitTree, - public val resolver: Resolver + public val resolver: Resolver, ) : AnalysisContextWithoutResolver(context, types, elements) { public companion object { public operator fun invoke(task: BasicJavacTask, unit: CompilationUnitTree): AnalysisContext = diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaPlugin.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaPlugin.kt index 8c51478c..d43cb675 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaPlugin.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaPlugin.kt @@ -118,7 +118,7 @@ public class AnalysisJavaPlugin : Plugin { private fun SolverState.collectFromDsl( todo: List, ctx: AnalysisContext, - resolutionContext: JavaResolutionContext + resolutionContext: JavaResolutionContext, ) { val obtainedPackages = mutableListOf() todo.forEach { descriptor -> @@ -155,7 +155,7 @@ public class AnalysisJavaPlugin : Plugin { descr: JavaFunctionDescriptor, constraints: DeclarationConstraints, ctx: AnalysisContext, - resolutionContext: JavaResolutionContext + resolutionContext: JavaResolutionContext, ) = (node.modifiers as? JCTree.JCModifiers)?.let { modifiers -> addConstraints(modifiers, "arrow.analysis.Pre", constraints.pre, ctx) @@ -171,7 +171,7 @@ public class AnalysisJavaPlugin : Plugin { modifiers: JCTree.JCModifiers, type: String, constraints: List, - ctx: AnalysisContext + ctx: AnalysisContext, ) { if (constraints.isNotEmpty()) { modifiers.addAnn { @@ -181,7 +181,7 @@ public class AnalysisJavaPlugin : Plugin { constraints.map { it.formula.toString() }, constraints.flatMap { solver.formulaManager.fieldNames(it.formula).map { fld -> fld.first }.toSet() - } + }, ) } } @@ -190,26 +190,26 @@ public class AnalysisJavaPlugin : Plugin { private fun addSubjectConstraint( modifiers: JCTree.JCModifiers, subject: String, - ctx: AnalysisContext + ctx: AnalysisContext, ): Unit = modifiers.addAnn { ctx.annStrings("arrow.analysis.Subject", subject) } private fun SolverState.collectFromAnnotations( todo: List, ctx: AnalysisContext, - resolutionContext: JavaResolutionContext + resolutionContext: JavaResolutionContext, ): Unit = ctx.elements.allModuleElements.forEach { module -> collectConstraintsFromAnnotations( todo.map { it.model(ctx) }, module.model(ctx), - resolutionContext + resolutionContext, ) } private fun SolverState.checkConstraints( unit: CompilationUnitTree, ctx: AnalysisContext, - resolutionContext: JavaResolutionContext + resolutionContext: JavaResolutionContext, ) { if (!hadParseErrors()) { unit.visitRecursively( diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaProcessor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaProcessor.kt index 23796bbc..1641b6d4 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaProcessor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisJavaProcessor.kt @@ -20,6 +20,7 @@ public object AnalysisJavaProcessorKey : Context.Key>() { override fun equals(other: Any?): Boolean { return other?.javaClass?.name == "arrow.meta.plugins.analysis.java.AnalysisJavaProcessorKey" } + override fun hashCode(): Int = 12345 } @@ -28,7 +29,9 @@ public class AnalysisJavaProcessor : Processor { public val todo: MutableList = mutableListOf() override fun getSupportedOptions(): MutableSet = mutableSetOf() + override fun getSupportedAnnotationTypes(): MutableSet = mutableSetOf("*") + override fun getSupportedSourceVersion(): SourceVersion = SourceVersion.latestSupported() override fun init(processingEnv: ProcessingEnvironment) { @@ -37,7 +40,7 @@ public class AnalysisJavaProcessor : Processor { override fun process( annotations: MutableSet, - roundEnv: RoundEnvironment + roundEnv: RoundEnvironment, ): Boolean { todo.addAll(roundEnv.rootElements) return false @@ -47,6 +50,6 @@ public class AnalysisJavaProcessor : Processor { element: Element?, annotation: AnnotationMirror?, member: ExecutableElement?, - userText: String? + userText: String?, ): MutableIterable = mutableListOf() } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisMessages.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisMessages.kt index 1aef0010..1d4e5f2d 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisMessages.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/AnalysisMessages.kt @@ -30,7 +30,7 @@ public class AnalysisMessages : ListResourceBundle() { UnsatInvariants, LiskovProblem, ErrorParsingPredicate, - AnalysisException + AnalysisException, ) public val Warnings: List = @@ -38,7 +38,7 @@ public class AnalysisMessages : ListResourceBundle() { InconsistentCallPost, InconsistentConditions, UnsupportedElement, - WarningParsingPredicate + WarningParsingPredicate, ) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/Resolver.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/Resolver.kt index 880dd6a0..eac980b5 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/Resolver.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/Resolver.kt @@ -17,9 +17,13 @@ public class Resolver(task: JavaCompiler.CompilationTask, private val unit: Comp get() = trees.getElement(TreePath(unit)) public fun path(tree: Tree): TreePath = TreePath.getPath(unit, tree) + public fun resolve(tree: Tree): Element? = trees.getElement(path(tree)) + public fun resolveType(tree: Tree): TypeMirror? = trees.getTypeMirror(path(tree)) + public fun tree(element: Element): Tree? = trees.getTree(element) + public fun parent(tree: Tree): Tree? = path(tree).parentPath.leaf public fun positionOf(tree: Tree): Pair = diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/TaskListener.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/TaskListener.kt index 991a902b..18557962 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/TaskListener.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/TaskListener.kt @@ -19,8 +19,11 @@ public abstract class PerKindTaskListener : TaskListener { } public fun afterParse(e: TaskEvent): Unit {} + public fun afterEnter(e: TaskEvent): Unit {} + public fun afterAnalyze(e: TaskEvent): Unit {} + public fun afterGenerate(e: TaskEvent): Unit {} } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/AnnotationUtils.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/AnnotationUtils.kt index d9e370e0..02f22046 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/AnnotationUtils.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/AnnotationUtils.kt @@ -32,7 +32,7 @@ public fun AnalysisContext.annArrays(type: String, vararg args: List): J ty(type), args .map { strings -> factory.NewArray(null, null, strings.map { factory.Literal(it) }.javac()) } - .javac() + .javac(), ) } @@ -66,7 +66,7 @@ public fun AnalysisContext.hintsPackage( emptyJavacList(), null, emptyJavacList(), - emptyJavacList() + emptyJavacList(), ) predefClassDef.sym = symbolTable.predefClass @@ -96,7 +96,7 @@ public fun AnalysisContext.hintsClass(hints: List): JCTree.JCClassDecl { emptyJavacList(), null, emptyJavacList(), - emptyJavacList() + emptyJavacList(), ) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaInterpreter.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaInterpreter.kt index c9911aff..2bbad886 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaInterpreter.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaInterpreter.kt @@ -147,8 +147,9 @@ public fun A.model(ctx: AnalysisContext): B = } public fun < - A : Tree, B : arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.Element> A - .modelCautious(ctx: AnalysisContext): B? = + A : Tree, + B : arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.Element, +> A.modelCautious(ctx: AnalysisContext): B? = when (this) { is CompilationUnitTree, is PackageTree, @@ -160,8 +161,9 @@ public fun < } public fun < - A : Tree, B : arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.Element> A - .model(ctx: AnalysisContext): B = + A : Tree, + B : arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.Element, +> A.model(ctx: AnalysisContext): B = when (this) { is ArrayTypeTree, is ParameterizedTypeTree, diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaResolutionContext.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaResolutionContext.kt index 4cf023cf..e1924dbc 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaResolutionContext.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/JavaResolutionContext.kt @@ -32,7 +32,7 @@ import com.sun.tools.javac.util.JCDiagnostic public class JavaResolutionContext( private val state: SolverState?, - private val ctx: AnalysisContext + private val ctx: AnalysisContext, ) : ResolutionContext { override val types: Types = object : Types { diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotationDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotationDescriptor.kt index a82699cd..cc8eeb62 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotationDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotationDescriptor.kt @@ -13,7 +13,7 @@ import javax.lang.model.element.AnnotationValue public class JavaAnnotationDescriptor( private val ctx: AnalysisContext, - private val impl: AnnotationMirror + private val impl: AnnotationMirror, ) : AnnotationDescriptor { private val inside: Map get() = @@ -36,6 +36,7 @@ public class JavaAnnotationDescriptor( override val fqName: FqName get() = FqName(impl.annotationType.asElement().fqName) + override val type: Type get() = impl.annotationType.model(ctx) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotations.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotations.kt index 46729cdf..24bd2f43 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotations.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaAnnotations.kt @@ -10,13 +10,15 @@ import javax.lang.model.element.AnnotationMirror public class JavaAnnotations( private val ctx: AnalysisContext, - override val impl: List + override val impl: List, ) : Annotations { override fun isEmpty(): Boolean = impl.isEmpty() + override fun iterable(): Iterable = impl.map { JavaAnnotationDescriptor(ctx, it) } override fun findAnnotation(fqName: FqName): AnnotationDescriptor? = iterable().firstOrNull { it.fqName == fqName } + override fun hasAnnotation(fqName: FqName): Boolean = findAnnotation(fqName) != null } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaClassDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaClassDescriptor.kt index b939e314..2017c98d 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaClassDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaClassDescriptor.kt @@ -27,8 +27,10 @@ public class JavaClassDescriptor(private val ctx: AnalysisContext, private val i override val unsubstitutedMemberScope: MemberScope get() = memberScope { it !is TypeElement && !it.modifiers.contains(Modifier.STATIC) } + override val staticScope: MemberScope get() = memberScope { it !is TypeElement && it.modifiers.contains(Modifier.STATIC) } + override val unsubstitutedInnerClassesScope: MemberScope get() = memberScope { it is TypeElement } @@ -51,13 +53,16 @@ public class JavaClassDescriptor(private val ctx: AnalysisContext, private val i (listOfNotNull(impl.superclass.takeIf { it.kind != TypeKind.NONE }) + impl.interfaces).map { it.model(ctx) } + override val declaredTypeParameters: List get() = impl.typeParameters.map { it.model(ctx) } override val typeConstructor: TypeConstructor get() = JavaTypeConstructor(ctx, impl) + override val defaultType: Type get() = ctx.types.getDeclaredType(impl).model(ctx) + override val thisAsReceiverParameter: ReceiverParameterDescriptor get() = JavaReceiverParameterDescriptor(ctx, impl.asType(), impl.enclosingElement) @@ -66,6 +71,7 @@ public class JavaClassDescriptor(private val ctx: AnalysisContext, private val i override val isInline: Boolean = false override val isFun: Boolean get() = ctx.types.isSubtype(impl.asType(), ctx.symbolTable.functionalInterfaceType) + override val isValue: Boolean = false override val isEnumEntry: Boolean = false override val isInner: Boolean = impl.nestingKind == NestingKind.MEMBER diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaConstructorDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaConstructorDescriptor.kt index 82f4d4bd..7a960252 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaConstructorDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaConstructorDescriptor.kt @@ -12,7 +12,7 @@ import javax.lang.model.element.ExecutableElement public class JavaConstructorDescriptor( private val ctx: AnalysisContext, - private val impl: ExecutableElement + private val impl: ExecutableElement, ) : ConstructorDescriptor, JavaFunctionDescriptor(ctx, impl) { init { require(impl.kind == ElementKind.CONSTRUCTOR) @@ -20,5 +20,6 @@ public class JavaConstructorDescriptor( override val constructedClass: ClassDescriptor get() = (impl as? Symbol.MethodSymbol)?.owner?.model(ctx)!! + override val isPrimary: Boolean = false } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaDescriptor.kt index bb86a7d1..c1633528 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaDescriptor.kt @@ -17,6 +17,7 @@ public open class JavaDescriptor(private val ctx: AnalysisContext, private val i override val containingDeclaration: DeclarationDescriptor get() = impl.enclosingElement.model(ctx) + override val containingPackage: FqName get() = FqName(impl.enclosingElement.fqName) diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaEnumConstantDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaEnumConstantDescriptor.kt index 2f278fce..12e698a1 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaEnumConstantDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaEnumConstantDescriptor.kt @@ -20,7 +20,7 @@ import javax.lang.model.element.VariableElement public class JavaEnumConstantDescriptor( private val ctx: AnalysisContext, - private val impl: VariableElement + private val impl: VariableElement, ) : ClassDescriptor, JavaMemberDescriptor(ctx, impl) { private val enclosingType = impl.enclosingElement.asType() @@ -30,13 +30,15 @@ public class JavaEnumConstantDescriptor( ctx, impl.enclosingElement.enclosedElements.filter { it.kind != ElementKind.ENUM_CONSTANT && predicate(it) - } + }, ) override val unsubstitutedMemberScope: MemberScope get() = memberScope { it !is TypeElement && !it.modifiers.contains(Modifier.STATIC) } + override val staticScope: MemberScope get() = memberScope { it !is TypeElement && it.modifiers.contains(Modifier.STATIC) } + override val unsubstitutedInnerClassesScope: MemberScope get() = memberScope { it is TypeElement } @@ -46,12 +48,15 @@ public class JavaEnumConstantDescriptor( override val superTypes: Collection get() = listOf(enclosingType.model(ctx)) + override val declaredTypeParameters: List = emptyList() override val typeConstructor: TypeConstructor get() = JavaTypeConstructor(ctx, impl.enclosingElement as TypeElement) + override val defaultType: Type get() = enclosingType.model(ctx) + override val thisAsReceiverParameter: ReceiverParameterDescriptor get() = JavaReceiverParameterDescriptor(ctx, enclosingType, impl.enclosingElement) @@ -60,6 +65,7 @@ public class JavaEnumConstantDescriptor( override val isInline: Boolean = false override val isFun: Boolean get() = ctx.types.isSubtype(impl.asType(), ctx.symbolTable.functionalInterfaceType) + override val isValue: Boolean = false override val isEnumEntry: Boolean = false override val isInner: Boolean = true diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFieldDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFieldDescriptor.kt index a4acd7d4..31d675b3 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFieldDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFieldDescriptor.kt @@ -23,7 +23,7 @@ import javax.lang.model.element.VariableElement public class JavaFieldDescriptor( private val ctx: AnalysisContext, - private val impl: VariableElement + private val impl: VariableElement, ) : PropertyDescriptor, JavaMemberDescriptor(ctx, impl) { init { require(impl.kind == ElementKind.FIELD) @@ -58,6 +58,7 @@ public class JavaFieldDescriptor( get() = if (impl.modifiers.contains(Modifier.STATIC)) null else JavaReceiverParameterDescriptor(ctx, impl.enclosingClass!!.asType(), impl) + override val typeParameters: List = emptyList() override val returnType: Type = type override val valueParameters: List = emptyList() diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFunctionDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFunctionDescriptor.kt index cedc5a58..336f29b3 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFunctionDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaFunctionDescriptor.kt @@ -21,7 +21,7 @@ import javax.lang.model.type.TypeKind public open class JavaFunctionDescriptor( private val ctx: AnalysisContext, - private val impl: ExecutableElement + private val impl: ExecutableElement, ) : FunctionDescriptor, JavaMemberDescriptor(ctx, impl) { override val isOperator: Boolean = false @@ -43,12 +43,16 @@ public open class JavaFunctionDescriptor( } else -> null } + override val typeParameters: List get() = impl.typeParameters.map { it.model(ctx) } + override val returnType: Type? get() = impl.returnType?.modelCautious(ctx) + override val valueParameters: List get() = impl.parameters.map { it.model(ctx) } + override val allParameters: List get() = listOfNotNull(dispatchReceiverParameter) + valueParameters diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaMemberScope.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaMemberScope.kt index e11a044d..dbde3a22 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaMemberScope.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaMemberScope.kt @@ -15,10 +15,12 @@ import javax.lang.model.element.VariableElement public class JavaMemberScope( private val ctx: AnalysisContext, - private val enclosedElements: Collection + private val enclosedElements: Collection, ) : MemberScope { override fun getClassifierNames(): Set = getNames() + override fun getFunctionNames(): Set = getNames() + override fun getVariableNames(): Set = getNames() private inline fun getNames(): Set = diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaModuleDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaModuleDescriptor.kt index 811dbb55..b4df110e 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaModuleDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaModuleDescriptor.kt @@ -11,7 +11,7 @@ import javax.lang.model.element.PackageElement public class JavaModuleDescriptor( private val ctx: AnalysisContext, - private val impl: ModuleElement + private val impl: ModuleElement, ) : JavaDescriptor(ctx, impl), ModuleDescriptor { override fun getPackage(pck: String): PackageViewDescriptor? = impl.enclosedElements diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaPackageDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaPackageDescriptor.kt index fdfa5014..c8b4e8d7 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaPackageDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaPackageDescriptor.kt @@ -11,10 +11,11 @@ import javax.lang.model.element.PackageElement public class JavaPackageDescriptor( private val ctx: AnalysisContext, - private val impl: PackageElement + private val impl: PackageElement, ) : PackageViewDescriptor, PackageFragmentDescriptor, JavaDescriptor(ctx, impl) { override val fqName: FqName get() = FqName(impl.fqName) + override val memberScope: MemberScope get() = JavaMemberScope(ctx, impl.enclosedElements) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaParameterDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaParameterDescriptor.kt index 40f07147..3428c343 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaParameterDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaParameterDescriptor.kt @@ -23,5 +23,6 @@ public class JavaParameterDescriptor(ctx: AnalysisContext, private val impl: Var override val varargElementType: Type? = null override fun declaresDefaultValue(): Boolean = impl.constantValue != null + override val defaultValue: Expression? = null // TODO: implement this!! } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaReceiverParameterDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaReceiverParameterDescriptor.kt index de39c541..153263c3 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaReceiverParameterDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaReceiverParameterDescriptor.kt @@ -21,7 +21,7 @@ import javax.lang.model.type.TypeMirror public class JavaReceiverParameterDescriptor( private val ctx: AnalysisContext, private val ty: TypeMirror, - private val enclosing: javax.lang.model.element.Element + private val enclosing: javax.lang.model.element.Element, ) : ReceiverParameterDescriptor { override fun impl(): TypeMirror = ty @@ -30,6 +30,7 @@ public class JavaReceiverParameterDescriptor( override val type: Type get() = ty.model(ctx) + override val value: ReceiverValue get() = object : ReceiverValue { @@ -37,12 +38,14 @@ public class JavaReceiverParameterDescriptor( override val isClassReceiver: Boolean get() = false // TODO check this later } + override val allParameters: List = emptyList() override val extensionReceiverParameter: ReceiverParameterDescriptor? = null override val dispatchReceiverParameter: ReceiverParameterDescriptor? = null override val typeParameters: List = emptyList() override val returnType: Type get() = type + override val valueParameters: List = emptyList() override val overriddenDescriptors: Collection = emptyList() @@ -53,5 +56,6 @@ public class JavaReceiverParameterDescriptor( get() = containingDeclaration.containingPackage override fun element(): Element? = null + override fun annotations(): Annotations = JavaAnnotations(ctx, emptyList()) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaTypeParameterDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaTypeParameterDescriptor.kt index 8ee098dc..30aafb25 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaTypeParameterDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaTypeParameterDescriptor.kt @@ -13,11 +13,12 @@ import javax.lang.model.element.TypeParameterElement public class JavaTypeParameterDescriptor( private val ctx: AnalysisContext, - private val impl: TypeParameterElement + private val impl: TypeParameterElement, ) : TypeParameterDescriptor, JavaMemberDescriptor(ctx, impl) { override val upperBounds: List get() = impl.bounds.map { it.model(ctx) } + override val index: Int get() = impl.enclosingElement.typeParametersFromEverywhere.indexOf(impl) @@ -27,6 +28,7 @@ public class JavaTypeParameterDescriptor( override val typeConstructor: TypeConstructor get() = JavaTypeParameterConstructor(ctx, impl) + override val defaultType: Type get() = impl.asType().model(ctx) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaValueDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaValueDescriptor.kt index fb72fb8b..75e4b513 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaValueDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaValueDescriptor.kt @@ -16,7 +16,7 @@ import javax.lang.model.element.VariableElement public open class JavaValueDescriptor( private val ctx: AnalysisContext, - private val impl: VariableElement + private val impl: VariableElement, ) : ValueDescriptor, JavaMemberDescriptor(ctx, impl) { override val type: Type @@ -25,6 +25,7 @@ public open class JavaValueDescriptor( is Symbol -> impl.type.model(ctx) else -> throw IllegalStateException("this element should be a symbol") } + override val allParameters: List = emptyList() override val extensionReceiverParameter: ReceiverParameterDescriptor? = null override val dispatchReceiverParameter: ReceiverParameterDescriptor? = null diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaVariableDescriptor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaVariableDescriptor.kt index ffb77104..49ed46f0 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaVariableDescriptor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/descriptors/JavaVariableDescriptor.kt @@ -17,6 +17,7 @@ public open class JavaVariableDescriptor(ctx: AnalysisContext, private val impl: ElementKind.FIELD -> true else -> false } + override val isConst: Boolean = impl.constantValue != null override val isLateInit: Boolean = false } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAsIs.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAsIs.kt index f25e03f3..6b0ef2ec 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAsIs.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAsIs.kt @@ -17,10 +17,13 @@ public class JavaTypeCast(private val ctx: AnalysisContext, private val impl: Ty TypeCastExpression, JavaElement(ctx, impl) { override val left: Expression get() = impl.expression.model(ctx) + override val right: TypeReference get() = impl.type.model(ctx) + override val operationToken: String get() = "as" + override val operationReference: SimpleNameExpression get() = JavaFakeReference("as", this) @@ -33,8 +36,10 @@ public class JavaInstanceOf(private val ctx: AnalysisContext, private val impl: IsExpression, JavaElement(ctx, impl) { override val leftHandSide: Expression get() = impl.expression.model(ctx) + override val typeReference: TypeReference? get() = JavaTypeReference(ctx, impl.type) + override val operationReference: SimpleNameExpression get() = JavaFakeReference("instanceof", this) diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAssert.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAssert.kt index 4301763d..cdc40311 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAssert.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAssert.kt @@ -29,8 +29,10 @@ public class JavaAssert(private val ctx: AnalysisContext, private val impl: Asse AssertExpression, JavaElement(ctx, impl) { override fun getResolvedCall(context: ResolutionContext): ResolvedCall = JavaAssertFakeCall(ctx, impl) + override val condition: Expression get() = impl.condition.model(ctx) + override val detail: Expression? get() = impl.detail?.model(ctx) } @@ -39,6 +41,7 @@ public class JavaAssertFakeCall(private val ctx: AnalysisContext, private val im ResolvedCall { override val callElement: Element get() = impl.model(ctx) + override val typeArguments: Map get() = emptyMap() @@ -54,7 +57,7 @@ public class JavaAssertFakeCall(private val ctx: AnalysisContext, private val im fakeDescriptor.predicateParameter to JavaExpressionValueArgument(ctx, impl.condition, fakeDescriptor.predicateParameter), fakeDescriptor.messageParameter to - JavaExpressionValueArgument(ctx, impl.detail, fakeDescriptor.messageParameter) + JavaExpressionValueArgument(ctx, impl.detail, fakeDescriptor.messageParameter), ) } else { mapOf( @@ -66,13 +69,14 @@ public class JavaAssertFakeCall(private val ctx: AnalysisContext, private val im override fun getReturnType(): Type = ctx.symbolTable.voidType.model(ctx) override fun getReceiverExpression(): Expression? = null + override val dispatchReceiver: ReceiverValue? = null override val extensionReceiver: ReceiverValue? = null } public class JavaAssertFakeDescriptor( private val ctx: AnalysisContext, - private val withDetail: Boolean + private val withDetail: Boolean, ) : CallableDescriptor { override fun impl(): Any = this @@ -94,9 +98,11 @@ public class JavaAssertFakeDescriptor( override val allParameters: List = valueParameters override fun annotations(): Annotations = JavaAnnotations(ctx, emptyList()) + override val overriddenDescriptors: Collection = emptyList() override val containingDeclaration: DeclarationDescriptor? = null override val containingPackage: FqName? = null + override fun element(): Element? = null } @@ -105,21 +111,25 @@ public class JavaAssertFakeParameter( public override val index: Int, name: String, private val typeMirror: TypeMirror, - override val containingDeclaration: DeclarationDescriptor + override val containingDeclaration: DeclarationDescriptor, ) : ValueParameterDescriptor { override fun impl(): Any = this override val type: Type get() = typeMirror.model(ctx) + override val returnType: Type get() = type + override val fqNameSafe: FqName = FqName(name) override val name: Name = Name(name) override val isCrossinline: Boolean = false override val isNoinline: Boolean = false override val varargElementType: Type? = null + override fun declaresDefaultValue(): Boolean = false + override val defaultValue: Expression? = null override val isVar: Boolean = false override val isConst: Boolean = false @@ -133,6 +143,8 @@ public class JavaAssertFakeParameter( override val overriddenDescriptors: Collection = emptyList() override val containingPackage: FqName? = null + override fun element(): Element? = null + override fun annotations(): Annotations = JavaAnnotations(ctx, emptyList()) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAssignment.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAssignment.kt index 40c05943..6366e0a2 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAssignment.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaAssignment.kt @@ -17,6 +17,7 @@ public class JavaAssignment(private val ctx: AnalysisContext, private val impl: AssignmentExpression, JavaElement(ctx, impl) { override val left: Expression get() = impl.variable.model(ctx) + override val right: Expression get() = impl.expression.model(ctx) @@ -31,10 +32,11 @@ public class JavaAssignment(private val ctx: AnalysisContext, private val impl: // are translated as "var = var op exp" public class JavaCompoundAssignment( private val ctx: AnalysisContext, - private val impl: CompoundAssignmentTree + private val impl: CompoundAssignmentTree, ) : AssignmentExpression, JavaElement(ctx, impl) { override val left: Expression get() = impl.variable.model(ctx) + override val right: Expression get() = JavaCompoundAssignmentRHS(ctx, impl) @@ -47,7 +49,7 @@ public class JavaCompoundAssignment( public class JavaCompoundAssignmentRHS( private val ctx: AnalysisContext, - private val impl: CompoundAssignmentTree + private val impl: CompoundAssignmentTree, ) : BinaryExpression, JavaElement(ctx, impl) { private val operatorName: String = compoundkindNames[impl.kind] ?: "UNKNOWN" @@ -60,10 +62,13 @@ public class JavaCompoundAssignmentRHS( is JCTree.JCAssignOp -> impl.operator.name.toString() else -> operatorName } + override val operationTokenRpr: String get() = operatorName + override val left: Expression get() = impl.variable.model(ctx) + override val right: Expression get() = impl.expression.model(ctx) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaBlock.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaBlock.kt index 4bf186b7..451d441b 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaBlock.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaBlock.kt @@ -14,12 +14,14 @@ import com.sun.source.tree.Tree public open class JavaBlockParent( private val ctx: AnalysisContext, private val elements: List, - owner: Tree + owner: Tree, ) : BlockExpression, JavaElement(ctx, owner) { override val statements: List get() = elements.map { it.model(ctx) } + override val firstStatement: Expression? get() = statements.firstOrNull() + override val implicitReturnFromLast: Boolean = false } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaCall.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaCall.kt index 57103978..b90ec211 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaCall.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaCall.kt @@ -25,10 +25,13 @@ public class JavaCall(private val ctx: AnalysisContext, private val impl: Method CallExpression, JavaElement(ctx, impl) { override val calleeExpression: Expression? get() = this.getResolvedCall()?.getReceiverExpression() + override val typeArguments: List get() = impl.typeArguments.mapNotNull { JavaTypeProjection(ctx, it) } + override val valueArguments: List get() = this.getResolvedCall()?.valueArguments?.flatMap { it.value.arguments }.orEmpty() + // Java does not have final block arguments override val lambdaArguments: List get() = emptyList() @@ -39,8 +42,10 @@ public class JavaConstructorCall(private val ctx: AnalysisContext, private val i override val calleeExpression: Expression? = null override val typeArguments: List get() = impl.typeArguments.mapNotNull { JavaTypeProjection(ctx, it) } + override val valueArguments: List get() = this.getResolvedCall()?.valueArguments?.flatMap { it.value.arguments }.orEmpty() + // Java does not have final block arguments override val lambdaArguments: List get() = emptyList() @@ -48,14 +53,17 @@ public class JavaConstructorCall(private val ctx: AnalysisContext, private val i public class JavaMemberSelect( private val ctx: AnalysisContext, - private val impl: MemberSelectTree + private val impl: MemberSelectTree, ) : CallExpression, JavaElement(ctx, impl) { override val calleeExpression: Expression? get() = impl.expression?.model(ctx) + override val typeArguments: List get() = emptyList() + override val valueArguments: List get() = emptyList() + // Java does not have final block arguments override val lambdaArguments: List get() = emptyList() @@ -82,10 +90,13 @@ public class JavaBinary(private val ctx: AnalysisContext, private val impl: Bina is JCTree.JCOperatorExpression -> impl.operator.name.toString() else -> operatorName } + override val operationTokenRpr: String get() = operatorName + override val left: Expression get() = impl.leftOperand.model(ctx) + override val right: Expression get() = impl.rightOperand.model(ctx) } @@ -119,5 +130,5 @@ internal val kindNames: Map = Tree.Kind.OR to "BITOR", Tree.Kind.XOR to "BITXOR", Tree.Kind.CONDITIONAL_AND to "ANDAND", - Tree.Kind.CONDITIONAL_OR to "OROR" + Tree.Kind.CONDITIONAL_OR to "OROR", ) diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaClass.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaClass.kt index e6ba6c44..622ff968 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaClass.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaClass.kt @@ -30,12 +30,14 @@ import com.sun.source.tree.Tree public class JavaInstanceInitializer( private val ctx: AnalysisContext, private val impl: BlockTree, - override val containingDeclaration: Declaration + override val containingDeclaration: Declaration, ) : AnonymousInitializer, JavaElement(ctx, impl) { override val body: Expression get() = impl.model(ctx) + override val name: String? get() = null + override val parents: List get() = listOf(containingDeclaration) + containingDeclaration.parents } @@ -45,12 +47,16 @@ public class JavaClass(private val ctx: AnalysisContext, private val impl: Class override val parents: List get() = ctx.resolver.parentTrees(impl).mapNotNull { it.modelCautious(ctx) } + override val name: String get() = impl.name.toString() + override val nameAsSafeName: Name get() = Name(name) + override val fqName: FqName get() = FqName(impl.fqName(ctx)) + override val nameAsName: Name get() = nameAsSafeName @@ -66,6 +72,7 @@ public class JavaClass(private val ctx: AnalysisContext, private val impl: Class else -> it.model(ctx) } } + override fun getAnonymousInitializers(): List = declarations.filterIsInstance() @@ -85,11 +92,14 @@ public class JavaClass(private val ctx: AnalysisContext, private val impl: Class // Java does not have many Kotlin niceties override fun getProperties(): List = emptyList() + override val companionObjects: List = emptyList() // we map all Java constructors as "secondary" override fun hasExplicitPrimaryConstructor(): Boolean = false + override fun hasPrimaryConstructor(): Boolean = false + override val primaryConstructor: PrimaryConstructor? = null override val primaryConstructorModifierList: ModifierList? = null override val primaryConstructorParameters: List = emptyList() @@ -98,14 +108,23 @@ public class JavaClass(private val ctx: AnalysisContext, private val impl: Class get() = declarations.filterIsInstance() override fun isAnnotation(): Boolean = impl.kind == Tree.Kind.ANNOTATION_TYPE + override fun isInterface(): Boolean = impl.kind == Tree.Kind.INTERFACE + override fun isEnum(): Boolean = impl.kind == Tree.Kind.ENUM + override fun isData(): Boolean = false + override fun isSealed(): Boolean = false + override fun isInner(): Boolean = ctx.resolver.parentTrees(impl).any { it is ClassTree } + override fun isInline(): Boolean = false + override fun isValue(): Boolean = false + override fun isTopLevel(): Boolean = !isInner() + override val isLocal: Boolean get() = ctx.resolver.parentTrees(impl).any { it is MethodTree } } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaConditional.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaConditional.kt index b224b2da..146dab5b 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaConditional.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaConditional.kt @@ -22,12 +22,14 @@ public abstract class JavaConditional( impl: Tree, private val conditionTree: ExpressionTree, private val thenTree: Tree, - private val elseTree: Tree? + private val elseTree: Tree?, ) : IfExpression, JavaElement(ctx, impl) { override val condition: Expression? get() = conditionTree.model(ctx) + override val thenExpression: Expression? get() = thenTree.model(ctx) + override val elseExpression: Expression? get() = elseTree?.model(ctx) } @@ -44,8 +46,10 @@ public class JavaSwitch(private val ctx: AnalysisContext, private val impl: Swit override val subjectVariable: Property? = null override val subjectExpression: Expression get() = impl.expression.model(ctx) + override val entries: List get() = impl.cases.map { it.model(ctx) } + override val elseExpression: Expression? get() = impl.cases.firstOrNull { it.expression == null }?.model(ctx)?.expression @@ -55,8 +59,10 @@ public class JavaCase(private val ctx: AnalysisContext, private val impl: CaseTr WhenEntry, JavaElement(ctx, impl) { override val isElse: Boolean get() = impl.expression == null + override val conditions: List get() = listOfNotNull(impl.expression?.model(ctx)) + override val expression: Expression get() = JavaBlockParent(ctx, impl.statements, impl) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaControlStatement.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaControlStatement.kt index 1c526005..2e02f000 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaControlStatement.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaControlStatement.kt @@ -22,8 +22,11 @@ public class JavaReturn(private val ctx: AnalysisContext, private val impl: Retu // no return labels in Java override val labeledExpression: Expression? = null + override fun getTargetLabel(): SimpleNameExpression? = null + override fun getLabelName(): String? = null + override fun getLabelNameAsName(): Name? = null } @@ -31,7 +34,9 @@ public class JavaContinue(ctx: AnalysisContext, private val impl: ContinueTree) ContinueExpression, JavaElement(ctx, impl) { override fun getTargetLabel(): SimpleNameExpression = JavaFakeReference(impl.label.toString(), this) + override fun getLabelName(): String = impl.label.toString() + override fun getLabelNameAsName(): Name = impl.label.name() } @@ -39,6 +44,8 @@ public class JavaBreak(ctx: AnalysisContext, private val impl: BreakTree) : BreakExpression, JavaElement(ctx, impl) { override fun getTargetLabel(): SimpleNameExpression = JavaFakeReference(impl.label.toString(), this) + override fun getLabelName(): String = impl.label.toString() + override fun getLabelNameAsName(): Name = impl.label.name() } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaElement.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaElement.kt index ef3cd9dc..58b3e25f 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaElement.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaElement.kt @@ -28,6 +28,7 @@ public open class JavaElement(private val ctx: AnalysisContext, private val impl get() = impl.toString() public fun getResolvedCall(): ResolvedCall? = impl.resolvedCall(ctx) + override fun getResolvedCall(context: ResolutionContext): ResolvedCall? = getResolvedCall() override fun getVariableDescriptor(context: ResolutionContext): VariableDescriptor? = null @@ -47,6 +48,7 @@ public open class JavaElement(private val ctx: AnalysisContext, private val impl is JCTree -> impl.type?.modelCautious(ctx) else -> null } + override fun type(context: ResolutionContext): Type? = type() override fun lastBlockStatementOrThis(): Expression = @@ -58,6 +60,7 @@ public open class JavaElement(private val ctx: AnalysisContext, private val impl override val modifierList: ModifierList? = null // TODO: fix later override fun getAnnotations(): List = modifierList?.annotations.orEmpty() + override val annotationEntries: List get() = modifierList?.annotationEntries.orEmpty() } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaException.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaException.kt index 28e24636..57ab953d 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaException.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaException.kt @@ -20,8 +20,10 @@ public open class JavaTry(private val ctx: AnalysisContext, private val impl: Tr TryExpression, JavaElement(ctx, impl) { override val tryBlock: BlockExpression get() = impl.block.model(ctx) + override val catchClauses: List get() = TODO("Not yet implemented") + override val finallyBlock: FinallySection? get() = impl.finallyBlock?.let { JavaFinally(ctx, it, impl) } } @@ -29,7 +31,7 @@ public open class JavaTry(private val ctx: AnalysisContext, private val impl: Tr public open class JavaFinally( private val ctx: AnalysisContext, private val impl: Tree, - private val owner: TryTree + private val owner: TryTree, ) : FinallySection, JavaElement(ctx, impl) { override val finalExpression: BlockExpression get() = @@ -43,12 +45,14 @@ public open class JavaCatch(private val ctx: AnalysisContext, private val impl: CatchClause, JavaElement(ctx, impl) { override val catchParameter: Parameter get() = JavaParameter(ctx, impl.parameter, null) + override val parameterList: ParameterList? get() = object : ParameterList { override val parameters: List = listOf(catchParameter) override val ownerFunction: DeclarationWithBody? = null } + override val catchBody: Expression? get() = impl.block.model(ctx) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaFakeReference.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaFakeReference.kt index 31171f11..d189a9e8 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaFakeReference.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaFakeReference.kt @@ -15,18 +15,25 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.types.Type public class JavaFakeReference(private val impl: String, private val parent: Element) : SimpleNameExpression { override fun getReferencedName(): String = impl + override fun getReferencedNameAsName(): Name = Name(impl) override fun type(context: ResolutionContext): Type? = null + override fun lastBlockStatementOrThis(): Expression = this override val text: String = impl + override fun impl(): Any = impl override fun getResolvedCall(context: ResolutionContext): ResolvedCall? = null + override fun getVariableDescriptor(context: ResolutionContext): VariableDescriptor? = null + override fun parents(): List = listOf(parent) + parent.parents() + override fun location(): CompilerMessageSourceLocation? = null + override val psiOrParent: Element get() = this } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaIdentifier.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaIdentifier.kt index e3911715..3756c714 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaIdentifier.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaIdentifier.kt @@ -17,7 +17,9 @@ public class JavaIdentifier(ctx: AnalysisContext, private val impl: IdentifierTr init { require(impl.name != ctx.names._this) } + override fun getReferencedName(): String = impl.name.toString() + override fun getReferencedNameAsName(): Name = impl.name.name() } @@ -28,7 +30,9 @@ public class JavaThis(ctx: AnalysisContext, impl: IdentifierTree) : } override fun getTargetLabel(): SimpleNameExpression? = null + override fun getLabelName(): String? = null + override fun getLabelNameAsName(): Name? = null } @@ -39,7 +43,10 @@ public class JavaSuper(ctx: AnalysisContext, impl: IdentifierTree) : } override val superTypeQualifier: TypeReference? = null + override fun getTargetLabel(): SimpleNameExpression? = null + override fun getLabelName(): String? = null + override fun getLabelNameAsName(): Name? = null } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLabeled.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLabeled.kt index 0903cb7a..4ec0334b 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLabeled.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLabeled.kt @@ -19,5 +19,6 @@ public class JavaLabeled(private val ctx: AnalysisContext, private val impl: Lab override fun getTargetLabel(): SimpleNameExpression? = null override fun getLabelName(): String? = impl.label?.toString() + override fun getLabelNameAsName(): Name? = impl.label?.name() } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLambda.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLambda.kt index 2b5e733a..fd7ad06c 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLambda.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLambda.kt @@ -37,11 +37,13 @@ public class JavaLambda(private val ctx: AnalysisContext, private val impl: Lamb override val valueParameters: List get() = impl.parameters.map { JavaParameter(ctx, it, this) } + override val valueParameterList: ParameterList get() = object : ParameterList { override val parameters: List get() = this@JavaLambda.valueParameters + override val ownerFunction: DeclarationWithBody get() = this@JavaLambda } @@ -50,11 +52,13 @@ public class JavaLambda(private val ctx: AnalysisContext, private val impl: Lamb override val receiverTypeReference: TypeReference? get() = null + override val typeReference: TypeReference? get() = null override val typeParameters: List get() = emptyList() + override val typeParameterList: TypeParameterList get() = object : TypeParameterList { @@ -64,6 +68,7 @@ public class JavaLambda(private val ctx: AnalysisContext, private val impl: Lamb override val typeConstraints: List get() = emptyList() + override val typeConstraintList: TypeConstraintList get() = object : TypeConstraintList { @@ -72,11 +77,15 @@ public class JavaLambda(private val ctx: AnalysisContext, private val impl: Lamb } override fun hasBody(): Boolean = impl.body != null + override fun body(): Expression = impl.body.model(ctx) + override val bodyExpression: Expression get() = body() + override val bodyBlockExpression: BlockExpression? get() = body() as? BlockExpression + override fun hasBlockBody(): Boolean = bodyBlockExpression != null override val isLocal: Boolean = true diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLoop.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLoop.kt index 9340b22b..ba0e8f7e 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLoop.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaLoop.kt @@ -20,6 +20,7 @@ public class JavaDoWhile(private val ctx: AnalysisContext, private val impl: DoW DoWhileExpression, JavaElement(ctx, impl) { override val condition: Expression get() = impl.condition.model(ctx) + override val body: Expression get() = impl.statement.model(ctx) } @@ -28,20 +29,24 @@ public class JavaWhile(private val ctx: AnalysisContext, private val impl: While WhileExpression, JavaElement(ctx, impl) { override val condition: Expression get() = impl.condition.model(ctx) + override val body: Expression get() = impl.statement.model(ctx) } public class JavaEnhancedFor( private val ctx: AnalysisContext, - private val impl: EnhancedForLoopTree + private val impl: EnhancedForLoopTree, ) : ForExpression, JavaElement(ctx, impl) { override val loopParameter: Parameter get() = JavaParameter(ctx, impl.variable, null) + override val destructuringDeclaration: DestructuringDeclaration? get() = null + override val loopRange: Expression get() = impl.expression.model(ctx) + override val body: Expression get() = impl.statement.model(ctx) } @@ -50,10 +55,13 @@ public class JavaFor(private val ctx: AnalysisContext, private val impl: ForLoop ThreePieceForExpression, JavaElement(ctx, impl) { override val initializer: List get() = impl.initializer.map { it.model(ctx) } + override val condition: Expression get() = impl.condition.model(ctx) + override val update: List get() = impl.update.map { it.model(ctx) } + override val body: Expression get() = impl.statement.model(ctx) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaMemberReference.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaMemberReference.kt index 202f2942..05059d66 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaMemberReference.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaMemberReference.kt @@ -11,12 +11,14 @@ import com.sun.source.tree.MemberReferenceTree public class JavaMemberReference( private val ctx: AnalysisContext, - private val impl: MemberReferenceTree + private val impl: MemberReferenceTree, ) : CallableReferenceExpression, JavaElement(ctx, impl) { override val callableReference: SimpleNameExpression get() = JavaFakeReference(impl.name.toString(), this) + override val receiverExpression: Expression? get() = impl.qualifierExpression?.model(ctx) + override val hasQuestionMarks: Boolean = false override val isEmptyLHS: Boolean get() = impl.qualifierExpression == null diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaMethod.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaMethod.kt index 46d02789..5aa0c2b9 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaMethod.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaMethod.kt @@ -32,12 +32,16 @@ public open class JavaMethod(private val ctx: AnalysisContext, private val impl: override val parents: List get() = ctx.resolver.parentTrees(impl).mapNotNull { it.modelCautious(ctx) } + override val name: String get() = impl.name.toString() + override val nameAsSafeName: Name get() = Name(name) + override val fqName: FqName get() = FqName(impl.fqName(ctx)) + override val nameAsName: Name get() = nameAsSafeName @@ -46,25 +50,32 @@ public open class JavaMethod(private val ctx: AnalysisContext, private val impl: override val bodyExpression: Expression? get() = impl.body?.model(ctx) + override fun hasBody(): Boolean = bodyExpression != null + override fun body(): Expression? = bodyExpression override fun hasInitializer(): Boolean = bodyExpression != null + override val initializer: Expression? get() = bodyExpression override val bodyBlockExpression: BlockExpression? get() = bodyExpression as? JavaBlock + override fun hasBlockBody(): Boolean = bodyBlockExpression != null override fun hasDeclaredReturnType(): Boolean = impl.returnType != null + override val typeReference: TypeReference? get() = impl.returnType?.let { JavaTypeReference(ctx, it) } + override val receiverTypeReference: TypeReference? get() = impl.receiverParameter?.type?.let { JavaTypeReference(ctx, it) } override val typeParameters: List get() = impl.typeParameters.map { JavaTypeParameter(ctx, it) } + override val typeParameterList: TypeParameterList get() = object : TypeParameterList { @@ -73,6 +84,7 @@ public open class JavaMethod(private val ctx: AnalysisContext, private val impl: override val valueParameters: List get() = impl.parameters.map { JavaParameter(ctx, it, this) } + override val valueParameterList: ParameterList get() = object : ParameterList { diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaParameterOrVariable.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaParameterOrVariable.kt index 693f27f6..25f6dbef 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaParameterOrVariable.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaParameterOrVariable.kt @@ -25,24 +25,29 @@ import javax.lang.model.element.Modifier public open class JavaParameterOrVariable( private val ctx: AnalysisContext, - private val impl: VariableTree + private val impl: VariableTree, ) : CallableDeclaration, JavaElement(ctx, impl) { override val text: String get() = name override val parents: List get() = ctx.resolver.parentTrees(impl).mapNotNull { it.modelCautious(ctx) } + override val name: String get() = impl.name.toString() + override val nameAsSafeName: Name get() = Name(name) + override val fqName: FqName get() = FqName(impl.fqName(ctx)) + override val nameAsName: Name get() = nameAsSafeName override val typeReference: TypeReference? get() = impl.type.model(ctx) + override val receiverTypeReference: TypeReference? = null override val valueParameters: List = emptyList() override val valueParameterList: ParameterList? = null @@ -56,23 +61,28 @@ public class JavaVariable(private val ctx: AnalysisContext, private val impl: Va VariableDeclaration, JavaParameterOrVariable(ctx, impl) { override val isVar: Boolean get() = !impl.modifiers.flags.contains(Modifier.FINAL) + override val initializer: Expression? get() = impl.initializer?.model(ctx) + override fun hasInitializer(): Boolean = impl.initializer != null } public class JavaParameter( private val ctx: AnalysisContext, private val impl: VariableTree, - public override val ownerFunction: DeclarationWithBody? + public override val ownerFunction: DeclarationWithBody?, ) : Parameter, JavaParameterOrVariable(ctx, impl) { override fun hasDefaultValue(): Boolean = impl.initializer != null + override val defaultValue: Expression? get() = impl.initializer?.model(ctx) override val isMutable: Boolean = false override val isVarArg: Boolean = false + override fun hasValOrVar(): Boolean = false + override val isLoopParameter: Boolean = false override val isCatchParameter: Boolean = false diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaParenthesized.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaParenthesized.kt index d2d12a38..cff9fd94 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaParenthesized.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaParenthesized.kt @@ -10,7 +10,7 @@ import com.sun.source.tree.ParenthesizedTree public class JavaParenthesized( private val ctx: AnalysisContext, - private val impl: ParenthesizedTree + private val impl: ParenthesizedTree, ) : ParenthesizedExpression, JavaElement(ctx, impl) { override val expression: Expression get() = impl.expression.model(ctx) diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedCall.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedCall.kt index 86bcf1d0..138a7c70 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedCall.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedCall.kt @@ -22,13 +22,14 @@ public class JavaResolvedCall( private val method: Symbol, private val receiver: Tree?, private val typeArgs: List, - private val arguments: List + private val arguments: List, ) : ResolvedCall { override val callElement: Element get() = whole.model(ctx) override fun getReceiverExpression(): JavaElement? = receiver?.model(ctx) + override val dispatchReceiver: ReceiverValue? get() = getReceiverExpression()?.let { @@ -38,11 +39,13 @@ public class JavaResolvedCall( get() = false // TODO check later } } + // there are no extension receivers in Java override val extensionReceiver: ReceiverValue? = null override val resultingDescriptor: CallableDescriptor get() = method.model(ctx) + override fun getReturnType(): Type = whole.model(ctx).type()!! override val typeArguments: Map @@ -51,6 +54,7 @@ public class JavaResolvedCall( .zip(typeArgs) .map { (descr, tree) -> descr to ctx.resolver.resolveType(tree)!!.model(ctx) } .toMap() + override val valueArguments: Map get() = resultingDescriptor.valueParameters @@ -68,7 +72,7 @@ public class JavaResolvedCall( public fun Tree.resolvedCall( ctx: AnalysisContext, additionalTypeArgs: List = emptyList(), - additionalArgs: List = emptyList() + additionalArgs: List = emptyList(), ): JavaResolvedCall? = when (this) { is JCTree.JCMethodInvocation -> // look inside @@ -81,7 +85,7 @@ public fun Tree.resolvedCall( it, null, additionalTypeArgs, - additionalArgs + argumentsFromEverywhere + additionalArgs + argumentsFromEverywhere, ) } is JCTree.JCMemberReference -> @@ -92,7 +96,7 @@ public fun Tree.resolvedCall( it, qualifierExpression, additionalTypeArgs + typeArguments, - additionalArgs + additionalArgs, ) } is JCTree.JCNewClass -> @@ -103,7 +107,7 @@ public fun Tree.resolvedCall( it, null, additionalTypeArgs + typeArguments, - additionalArgs + arguments + additionalArgs + arguments, ) } is JCTree.JCFieldAccess -> diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedValueArgument.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedValueArgument.kt index 5964e354..a12ab5c1 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedValueArgument.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaResolvedValueArgument.kt @@ -17,10 +17,11 @@ import com.sun.source.tree.Tree public class JavaExpressionValueArgument( private val ctx: AnalysisContext, private val impl: Tree, - private val descr: ValueParameterDescriptor + private val descr: ValueParameterDescriptor, ) : ExpressionValueArgument { override val valueArgument: ValueArgument get() = JavaValueArgument(impl.model(ctx), descr) + override val arguments: List get() = listOf(valueArgument) } @@ -29,20 +30,24 @@ public class JavaDefaultValueArgument(private val descr: ValueParameterDescripto DefaultValueArgument { override val valueArgument: ValueArgument? get() = descr.defaultValue?.let { JavaValueArgument(it, descr) } + override val arguments: List get() = listOfNotNull(valueArgument) } public open class JavaValueArgument( private val impl: Expression, - private val descr: ValueParameterDescriptor + private val descr: ValueParameterDescriptor, ) : ValueArgument { override val argumentExpression: Expression get() = impl + override fun getArgumentName(): ValueArgumentName = JavaValueArgumentName(descr) override fun isNamed(): Boolean = false + override fun isExternal(): Boolean = false + override val isSpread: Boolean = false } @@ -50,5 +55,6 @@ public class JavaValueArgumentName(private val descr: ValueParameterDescriptor) ValueArgumentName { override val asName: Name get() = descr.name + override val referenceExpression: SimpleNameExpression? = null } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaSourceLocation.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaSourceLocation.kt index 144ef505..f1c60075 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaSourceLocation.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaSourceLocation.kt @@ -8,18 +8,23 @@ import com.sun.source.tree.CompilationUnitTree public class JavaSourceLocation( private val unit: CompilationUnitTree, private val startPos: Long, - private val endPos: Long + private val endPos: Long, ) : CompilerMessageSourceLocation { override val column: Int get() = unit.lineMap.getColumnNumber(startPos).toInt() + override val columnEnd: Int get() = unit.lineMap.getColumnNumber(endPos).toInt() + override val line: Int get() = unit.lineMap.getLineNumber(startPos).toInt() + override val lineEnd: Int get() = unit.lineMap.getLineNumber(endPos).toInt() + override val lineContent: String? get() = null + override val path: String get() = unit.sourceFile.toUri().path @@ -27,7 +32,7 @@ public class JavaSourceLocation( public operator fun invoke( unit: CompilationUnitTree?, startPos: Long, - endPos: Long + endPos: Long, ): JavaSourceLocation? = unit?.let { JavaSourceLocation(it, startPos, endPos) } } } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaSynchronized.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaSynchronized.kt index cac8ee9c..c1c6fe46 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaSynchronized.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaSynchronized.kt @@ -11,10 +11,11 @@ import com.sun.source.tree.SynchronizedTree public class JavaSynchronized( private val ctx: AnalysisContext, - private val impl: SynchronizedTree + private val impl: SynchronizedTree, ) : SynchronizedExpression, JavaElement(ctx, impl) { override val subject: Expression get() = impl.expression.model(ctx) + override val block: BlockExpression get() = impl.block.model(ctx) } diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaTypeParameter.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaTypeParameter.kt index 88f02a1e..0b3fcf4a 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaTypeParameter.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/elements/JavaTypeParameter.kt @@ -11,7 +11,7 @@ import com.sun.source.tree.TypeParameterTree public class JavaTypeParameter( private val ctx: AnalysisContext, - private val impl: TypeParameterTree + private val impl: TypeParameterTree, ) : TypeParameter { override val variance: Variance = Variance.Invariant override val extendsBounds: List diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaType.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaType.kt index 478b51f3..a464da59 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaType.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaType.kt @@ -23,6 +23,7 @@ public class JavaType(private val ctx: AnalysisContext, internal val ty: TypeMir ) override fun isNullable(): Boolean = false + override val unwrappedNotNullableType: Type = this override val isMarkedNullable: Boolean = false @@ -32,6 +33,7 @@ public class JavaType(private val ctx: AnalysisContext, internal val ty: TypeMir object : OurTypeVisitor>(emptyList()) { override fun visitArray(t: ArrayType?, p: Unit?): List = listOfNotNull(t?.componentType).map { JavaTypeProjection(ctx, it) } + override fun visitDeclared(t: DeclaredType?, p: Unit?): List = t?.typeArguments?.map { JavaTypeProjection(ctx, it) }.orEmpty() } @@ -40,21 +42,32 @@ public class JavaType(private val ctx: AnalysisContext, internal val ty: TypeMir private fun isEqualTo(other: TypeMirror): Boolean = ctx.types.isSameType(ty, other) override fun isBoolean(): Boolean = isEqualTo(ctx.symbolTable.booleanType) + override fun isInt(): Boolean = isEqualTo(ctx.symbolTable.intType) + override fun isLong(): Boolean = isEqualTo(ctx.symbolTable.longType) + override fun isFloat(): Boolean = isEqualTo(ctx.symbolTable.floatType) + override fun isDouble(): Boolean = isEqualTo(ctx.symbolTable.doubleType) + override fun isByte(): Boolean = isEqualTo(ctx.symbolTable.byteType) + override fun isShort(): Boolean = isEqualTo(ctx.symbolTable.shortType) + override fun isUnsignedNumberType(): Boolean = false // TODO + override fun isChar(): Boolean = isEqualTo(ctx.symbolTable.charType) + override fun isString(): Boolean = isEqualTo(ctx.symbolTable.stringType) + override fun isAnyOrNullableAny(): Boolean = isEqualTo(ctx.symbolTable.objectType) override fun isSubtypeOf(other: Type): Boolean { if (other !is JavaType) return false return ctx.types.isSubtype(ty, other.ty) } + override fun isEqualTo(other: Type): Boolean { if (other !is JavaType) return false return ctx.types.isSameType(ty, other.ty) diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeConstructor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeConstructor.kt index 9bb77272..e25c81b4 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeConstructor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeConstructor.kt @@ -16,13 +16,16 @@ public class JavaTypeConstructor(private val ctx: AnalysisContext, private val i TypeConstructor { override val parameters: List get() = impl.typeParameters.map { it.model(ctx) } + override val supertypes: Collection get() = (listOfNotNull(impl.superclass.takeIf { it.kind != TypeKind.NONE }) + impl.interfaces).map { it.model(ctx) } + override val isFinal: Boolean get() = impl.modifiers.contains(Modifier.FINAL) + override val isDenotable: Boolean = true override val declarationDescriptor: ClassifierDescriptor get() = impl.model(ctx) diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeParameterConstructor.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeParameterConstructor.kt index 9a0d46b1..279dc47c 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeParameterConstructor.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeParameterConstructor.kt @@ -13,13 +13,15 @@ import javax.lang.model.element.TypeParameterElement public class JavaTypeParameterConstructor( private val ctx: AnalysisContext, - private val impl: TypeParameterElement + private val impl: TypeParameterElement, ) : TypeConstructor { override val parameters: List = emptyList() override val supertypes: Collection get() = impl.bounds.map { it.model(ctx) } + override val isFinal: Boolean get() = impl.modifiers.contains(Modifier.FINAL) + override val isDenotable: Boolean = true override val declarationDescriptor: ClassifierDescriptor get() = impl.model(ctx) diff --git a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeProjection.kt b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeProjection.kt index 2e7306ef..ca20386d 100644 --- a/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeProjection.kt +++ b/analysis/java-plugin/src/main/kotlin/arrow/meta/plugins/analysis/java/ast/types/JavaTypeProjection.kt @@ -14,6 +14,7 @@ public class JavaTypeProjection(private val ctx: AnalysisContext, private val ty override val projectionKind: Variance = Variance.Invariant override val type: Type get() = JavaType(ctx, ty) + override val isStarProjection: Boolean get() = ty.visit( diff --git a/analysis/java-plugin/src/test/kotlin/arrow/meta/plugins/analysis/java/AnalysisTests.kt b/analysis/java-plugin/src/test/kotlin/arrow/meta/plugins/analysis/java/AnalysisTests.kt index 50684e00..854cbcd4 100644 --- a/analysis/java-plugin/src/test/kotlin/arrow/meta/plugins/analysis/java/AnalysisTests.kt +++ b/analysis/java-plugin/src/test/kotlin/arrow/meta/plugins/analysis/java/AnalysisTests.kt @@ -17,7 +17,7 @@ class AnalysisTests { } """( withPlugin = { succeeded() }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -34,7 +34,7 @@ class AnalysisTests { } """( withPlugin = { succeeded() }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -54,7 +54,7 @@ class AnalysisTests { failed() hadErrorContaining("fails to satisfy the post-condition") }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -76,7 +76,7 @@ class AnalysisTests { failed() hadErrorContaining("fails to satisfy the post-condition") }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -97,7 +97,7 @@ class AnalysisTests { failed() hadErrorContaining("fails to satisfy the post-condition") }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -119,7 +119,7 @@ class AnalysisTests { } """( withPlugin = { succeeded() }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -144,7 +144,7 @@ class AnalysisTests { failed() hadErrorContaining("fails to satisfy the post-condition") }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -171,7 +171,7 @@ class AnalysisTests { } """( withPlugin = { succeeded() }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -201,7 +201,7 @@ class AnalysisTests { failed() hadErrorContaining("pre-condition `value is positive` is not satisfied") }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -232,7 +232,7 @@ class AnalysisTests { } """( withPlugin = { succeeded() }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -266,7 +266,7 @@ class AnalysisTests { failed() hadErrorContaining("pre-condition `value is positive` is not satisfied") }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } @@ -301,7 +301,7 @@ class AnalysisTests { failed() hadErrorContaining("pre-condition `result is positive` is not satisfied") }, - withoutPlugin = { succeeded() } + withoutPlugin = { succeeded() }, ) } } diff --git a/analysis/java-plugin/src/test/kotlin/arrow/meta/plugins/analysis/java/Utils.kt b/analysis/java-plugin/src/test/kotlin/arrow/meta/plugins/analysis/java/Utils.kt index a2075c34..f6a15095 100644 --- a/analysis/java-plugin/src/test/kotlin/arrow/meta/plugins/analysis/java/Utils.kt +++ b/analysis/java-plugin/src/test/kotlin/arrow/meta/plugins/analysis/java/Utils.kt @@ -7,17 +7,17 @@ import com.google.testing.compile.JavaFileObjects public operator fun String.invoke( withPlugin: CompilationSubject.() -> Unit, - withoutPlugin: CompilationSubject.() -> Unit + withoutPlugin: CompilationSubject.() -> Unit, ) = ("Example" to this)(withPlugin, withoutPlugin) public operator fun Pair.invoke( withPlugin: CompilationSubject.() -> Unit, - withoutPlugin: CompilationSubject.() -> Unit + withoutPlugin: CompilationSubject.() -> Unit, ) = mapOf(this)(withPlugin, withoutPlugin) public operator fun Map.invoke( withPlugin: CompilationSubject.() -> Unit, - withoutPlugin: CompilationSubject.() -> Unit + withoutPlugin: CompilationSubject.() -> Unit, ) { worker(config = { withOptions("-parameters") }, files = this, check = withoutPlugin) worker( @@ -26,19 +26,19 @@ public operator fun Map.invoke( "-parameters", "-Xplugin:" + AnalysisJavaPlugin.NAME + - " generatedSrcOutputDir=${System.getProperty("arrow.meta.generate.source.dir")}" + " generatedSrcOutputDir=${System.getProperty("arrow.meta.generate.source.dir")}", ) .withProcessors(AnalysisJavaProcessor()) }, files = this, - check = withPlugin + check = withPlugin, ) } private fun worker( config: Compiler.() -> Compiler = { this }, files: Map, - check: CompilationSubject.() -> Unit + check: CompilationSubject.() -> Unit, ): Unit { val compiler = Compiler.javac().config() val compilation = compiler.compile(files.map { (k, v) -> JavaFileObjects.forSourceString(k, v) }) diff --git a/analysis/kotlin-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisGradlePlugin.kt b/analysis/kotlin-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisGradlePlugin.kt index f7868b2a..4674a660 100644 --- a/analysis/kotlin-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisGradlePlugin.kt +++ b/analysis/kotlin-gradle-plugin/src/main/kotlin/arrow/meta/plugin/gradle/AnalysisGradlePlugin.kt @@ -18,7 +18,7 @@ public class AnalysisGradlePlugin : ArrowMetaGradlePlugin { if ( kotlinCompilation.compilationName.endsWith( KotlinCompilation.TEST_COMPILATION_NAME, - ignoreCase = true + ignoreCase = true, ) ) false diff --git a/analysis/kotlin-plugin/api/arrow-analysis-kotlin-plugin.api b/analysis/kotlin-plugin/api/arrow-analysis-kotlin-plugin.api index 90458e2f..954f6a3c 100644 --- a/analysis/kotlin-plugin/api/arrow-analysis-kotlin-plugin.api +++ b/analysis/kotlin-plugin/api/arrow-analysis-kotlin-plugin.api @@ -53,6 +53,7 @@ public final class arrow/meta/plugins/analysis/phases/Stage : java/lang/Enum { public static final field CollectConstraints Larrow/meta/plugins/analysis/phases/Stage; public static final field Init Larrow/meta/plugins/analysis/phases/Stage; public static final field Prove Larrow/meta/plugins/analysis/phases/Stage; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/Stage; public static fun values ()[Larrow/meta/plugins/analysis/phases/Stage; } @@ -67,6 +68,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin public fun getBindingContext ()Lorg/jetbrains/kotlin/resolve/BindingContext; public fun getKeys (Lorg/jetbrains/kotlin/util/slicedMap/WritableSlice;)Ljava/util/Collection; public fun getModule ()Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/descriptors/ModuleDescriptor; + public fun getProject ()Lorg/jetbrains/kotlin/com/intellij/openapi/project/Project; public fun getType (Lorg/jetbrains/kotlin/psi/KtExpression;)Lorg/jetbrains/kotlin/types/KotlinType; public fun getTypes ()Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/types/Types; public fun handleError (Larrow/meta/plugins/analysis/phases/analysis/solver/errors/ErrorIds;Larrow/meta/plugins/analysis/phases/analysis/solver/ast/context/elements/Element;Ljava/lang/String;)V @@ -2721,6 +2723,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin public static final field NONE Larrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProjectionKind; public static final field OUT Larrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProjectionKind; public static final field STAR Larrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProjectionKind; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProjectionKind; public static fun values ()[Larrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProjectionKind; } @@ -3651,6 +3654,7 @@ public final class arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin public final class arrow/meta/plugins/analysis/phases/ir/HintState : java/lang/Enum { public static final field NeedsProcessing Larrow/meta/plugins/analysis/phases/ir/HintState; public static final field Processed Larrow/meta/plugins/analysis/phases/ir/HintState; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Larrow/meta/plugins/analysis/phases/ir/HintState; public static fun values ()[Larrow/meta/plugins/analysis/phases/ir/HintState; } diff --git a/analysis/kotlin-plugin/build.gradle.kts b/analysis/kotlin-plugin/build.gradle.kts index c99d8858..13bbce7a 100644 --- a/analysis/kotlin-plugin/build.gradle.kts +++ b/analysis/kotlin-plugin/build.gradle.kts @@ -1,5 +1,8 @@ @file:Suppress("DSL_SCOPE_VIOLATION") +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + + plugins { id(libs.plugins.kotlin.jvm.get().pluginId) alias(libs.plugins.arrowGradleConfig.kotlin) @@ -15,22 +18,91 @@ kotlin { } } +sourceSets { + main { + java.setSrcDirs(listOf("src/main/java")) + resources.setSrcDirs(listOf("resources")) + } + test { + java.setSrcDirs(listOf("src/test", "src/test-gen")) + resources.setSrcDirs(listOf("testResources")) + } +} + dependencies { - compileOnly(libs.kotlin.stdlibJDK8) + implementation(libs.arrowMeta) - implementation(projects.arrowAnalysisTypes) implementation(projects.arrowAnalysisCommon) - testImplementation(libs.kotlin.stdlibJDK8) - testImplementation(libs.junit) - testImplementation(libs.junitEngine) - testImplementation(libs.junitPlatformLauncher) - testImplementation(libs.arrowMetaTest) - testRuntimeOnly(libs.arrowMeta) - testRuntimeOnly(projects.arrowAnalysisTypes) - testRuntimeOnly(projects.arrowAnalysisKotlinPlugin) - testRuntimeOnly(libs.arrowCore) - testImplementation(libs.ksp.api) testImplementation(libs.ksp.lib) + testImplementation(libs.arrowMetaTest) + testImplementation(projects.arrowAnalysisLaws) + + val kotlinVersion: String = libs.versions.kotlin.get() + + println("Kotlin version: $kotlinVersion") + + "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion".let { + compileOnly(it) + testImplementation(it) + } + + testRuntimeOnly("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") + testRuntimeOnly("org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion") + testRuntimeOnly("org.jetbrains.kotlin:kotlin-annotations-jvm:$kotlinVersion") + + testImplementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") + testImplementation("org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:$kotlinVersion") + testImplementation("junit:junit:4.13.2") + + testImplementation(platform("org.junit:junit-bom:5.8.0")) + testImplementation("org.junit.jupiter:junit-jupiter") + testImplementation("org.junit.platform:junit-platform-commons") + testImplementation("org.junit.platform:junit-platform-launcher") + testImplementation("org.junit.platform:junit-platform-runner") + testImplementation("org.junit.platform:junit-platform-suite-api") + +} + +tasks.test { + dependsOn(project(":arrow-analysis-types").tasks.getByName("jvmJar")) + dependsOn(project(":arrow-analysis-laws").tasks.getByName("jvmJar")) + useJUnitPlatform() + doFirst { + setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib", "kotlin-stdlib") + setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib-jdk8", "kotlin-stdlib-jdk8") + setLibraryProperty("org.jetbrains.kotlin.test.kotlin-reflect", "kotlin-reflect") + setLibraryProperty("org.jetbrains.kotlin.test.kotlin-test", "kotlin-test") + setLibraryProperty("org.jetbrains.kotlin.test.kotlin-script-runtime", "kotlin-script-runtime") + setLibraryProperty("org.jetbrains.kotlin.test.kotlin-annotations-jvm", "kotlin-annotations-jvm") + } +} + +tasks.withType().configureEach { + compilerOptions { + optIn.add("org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi") + optIn.add("org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI") + } +} + +val generateTests by tasks.registering(JavaExec::class) { + classpath = sourceSets.test.get().runtimeClasspath + mainClass.set("arrow.meta.plugins.analysis.GenerateTestsKt") +} + +val compileTestKotlin by tasks.getting { + doLast { + generateTests.get().exec() + } +} + +fun Test.setLibraryProperty(propName: String, jarName: String) { + val path = project.configurations + .testRuntimeClasspath.get() + .files + .find { """$jarName-\d.*jar""".toRegex().matches(it.name) } + ?.absolutePath + ?: return + systemProperty(propName, path) } diff --git a/analysis/kotlin-plugin/src/main/java/arrow/meta/plugins/analysis/errors/MetaErrors.java b/analysis/kotlin-plugin/src/main/java/arrow/meta/plugins/analysis/errors/MetaErrors.java index 4044768b..929a7fbd 100644 --- a/analysis/kotlin-plugin/src/main/java/arrow/meta/plugins/analysis/errors/MetaErrors.java +++ b/analysis/kotlin-plugin/src/main/java/arrow/meta/plugins/analysis/errors/MetaErrors.java @@ -1,6 +1,6 @@ package arrow.meta.plugins.analysis.errors; -import org.jetbrains.kotlin.com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElement; import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1; import org.jetbrains.kotlin.diagnostics.Errors; diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/AnalysisPlugin.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/AnalysisPlugin.kt index 86767357..9a3ed1ea 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/AnalysisPlugin.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/AnalysisPlugin.kt @@ -2,6 +2,13 @@ package arrow.meta import arrow.meta.phases.CompilerContext import arrow.meta.plugins.analysis.phases.analysisPhases +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.analysis.checkers.LanguageVersionSettingsCheckers +import org.jetbrains.kotlin.fir.analysis.checkers.declaration.DeclarationCheckers +import org.jetbrains.kotlin.fir.analysis.checkers.expression.ExpressionCheckers +import org.jetbrains.kotlin.fir.analysis.checkers.type.TypeCheckers +import org.jetbrains.kotlin.fir.analysis.extensions.FirAdditionalCheckersExtension +import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar class AnalysisPlugin : Meta() { override fun intercept(ctx: CompilerContext): List = @@ -9,3 +16,20 @@ class AnalysisPlugin : Meta() { } class AnalysisMetaCliProcessor : MetaCliProcessor("analysis") + +class FirAnalysisPluginRegistrar : FirExtensionRegistrar() { + override fun ExtensionRegistrarContext.configurePlugin() { + +::AnalysisChecker + } +} + +class AnalysisChecker(session: FirSession) : FirAdditionalCheckersExtension(session) { + override val declarationCheckers: DeclarationCheckers + get() = super.declarationCheckers + override val expressionCheckers: ExpressionCheckers + get() = super.expressionCheckers + override val typeCheckers: TypeCheckers + get() = super.typeCheckers + override val languageVersionSettingsCheckers: LanguageVersionSettingsCheckers + get() = super.languageVersionSettingsCheckers +} diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/Phases.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/Phases.kt index c03428bd..128e0035 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/Phases.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/Phases.kt @@ -42,7 +42,7 @@ internal fun Meta.analysisPhases(): ExtensionPhase = bindingTrace.bindingContext, module, emptyList(), - listOfNotNull(path) + listOfNotNull(path), ) } else -> null @@ -72,7 +72,7 @@ internal fun Meta.analysisPhases(): ExtensionPhase = bindingTrace.bindingContext, module, emptyList(), - listOf(path.absoluteFile) + listOf(path.absoluteFile), ) } else { // no need to create the hints file @@ -81,7 +81,7 @@ internal fun Meta.analysisPhases(): ExtensionPhase = bindingTrace.bindingContext, module, emptyList(), - emptyList() + emptyList(), ) } } @@ -144,14 +144,14 @@ internal fun Meta.analysisPhases(): ExtensionPhase = } null }, - irDumpKotlinLike() + irDumpKotlinLike(), ) ) enum class Stage { Init, CollectConstraints, - Prove + Prove, } object Keys { @@ -199,7 +199,7 @@ internal fun CompilerContext.initialize(module: ModuleDescriptor) { internal inline fun CompilerContext.ensureInitialized( key: String, - acquire: () -> A + acquire: () -> A, ) { val thing: A? = get(key) if (thing == null) { @@ -220,19 +220,19 @@ private fun CompilerContext.setHintsAs(module: ModuleDescriptor, state: HintStat private fun CompilerContext.isInStage( module: org.jetbrains.kotlin.descriptors.ModuleDescriptor, - stage: Stage + stage: Stage, ) = get(Keys.stage(module)) == stage private fun CompilerContext.setStageAs( module: org.jetbrains.kotlin.descriptors.ModuleDescriptor, - stage: Stage + stage: Stage, ) { set(Keys.stage(module), stage) } private fun CompilerContext.setParseWarningsAs( module: org.jetbrains.kotlin.descriptors.ModuleDescriptor, - warnings: List + warnings: List, ) { set(Keys.parseWarnings(module), warnings) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolutionContext.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolutionContext.kt index 0954202c..1725325c 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolutionContext.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/KotlinResolutionContext.kt @@ -18,8 +18,8 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.kotlin.descriptors import arrow.meta.plugins.analysis.phases.analysis.solver.ast.kotlin.types.KotlinType import arrow.meta.plugins.analysis.phases.analysis.solver.errors.ErrorIds import arrow.meta.plugins.analysis.phases.analysis.solver.state.SolverState +import com.intellij.psi.PsiElement import org.jetbrains.kotlin.cfg.getDeclarationDescriptorIncludingConstructors -import org.jetbrains.kotlin.com.intellij.psi.PsiElement import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtExpression @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.resolve.BindingTrace class KotlinResolutionContext( private val state: SolverState?, private val impl: BindingTrace, - private val moduleImpl: org.jetbrains.kotlin.descriptors.ModuleDescriptor + private val moduleImpl: org.jetbrains.kotlin.descriptors.ModuleDescriptor, ) : ResolutionContext, BindingTrace by impl { fun reportLiskovProblem(expression: Element, msg: String) { @@ -141,6 +141,7 @@ class KotlinResolutionContext( } private val descriptorCache: MutableMap> = mutableMapOf() + override fun descriptorFor(fqName: FqName): List { // add if not there yet if (!descriptorCache.containsKey(fqName.name)) { diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/ast/KotlinInterpreter.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/ast/KotlinInterpreter.kt index 3e8661ba..c3c587f3 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/ast/KotlinInterpreter.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/ast/KotlinInterpreter.kt @@ -137,8 +137,8 @@ fun A.model(): B = is KtModifierList -> KotlinModifierList(this).repr() // fallbacks is KtFunction -> KotlinDefaultFunction(this).repr() - is KtContainerNodeForControlStructureBody -> this.expression?.model() - ?: KotlinDefaultElement(this).repr() + is KtContainerNodeForControlStructureBody -> + this.expression?.model() ?: KotlinDefaultElement(this).repr() is KtContainerNode -> KotlinDefaultElement(this).repr() // final fallback for expressions is KtExpression -> KotlinDefaultExpression(this).repr() diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinAnnotated.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinAnnotated.kt index b47bf2df..3177001d 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinAnnotated.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinAnnotated.kt @@ -5,5 +5,6 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.descriptor fun interface KotlinAnnotated : Annotated { fun impl(): org.jetbrains.kotlin.descriptors.annotations.Annotated + override fun annotations(): Annotations = KotlinAnnotations(impl().annotations) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinCallableDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinCallableDescriptor.kt index 7164380d..beaeb9da 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinCallableDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinCallableDescriptor.kt @@ -29,18 +29,25 @@ fun interface KotlinCallableDescriptor : CallableDescriptor, KotlinDeclarationDe override val fqNameSafe: FqName get() = FqName(impl().fqNameSafe.asString()) + override val name: Name get() = Name(impl().name.asString()) + override val extensionReceiverParameter: ReceiverParameterDescriptor? get() = impl().extensionReceiverParameter?.model() + override val dispatchReceiverParameter: ReceiverParameterDescriptor? get() = impl().dispatchReceiverParameter?.model() + override val typeParameters: List get() = impl().typeParameters.map { it.model() } + override val returnType: Type? get() = impl().returnType?.let { KotlinType(it) } + override val valueParameters: List get() = impl().valueParameters.map { it.model() } + override val overriddenDescriptors: Collection get() = impl().overriddenDescriptors.map { it.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinCallableMemberDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinCallableMemberDescriptor.kt index a46325cb..e9f07407 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinCallableMemberDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinCallableMemberDescriptor.kt @@ -35,6 +35,7 @@ fun interface KotlinCallableMemberDescriptor : override val fqNameSafe: FqName get() = FqName(impl().fqNameSafe.asString()) + override val name: Name get() = Name(impl().name.asString()) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinClassDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinClassDescriptor.kt index f640eaaf..c0aa63ee 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinClassDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinClassDescriptor.kt @@ -15,19 +15,24 @@ class KotlinClassDescriptor(val impl: org.jetbrains.kotlin.descriptors.ClassDesc ClassDescriptor, KotlinDeclarationDescriptor, KotlinClassifierDescriptorWithTypeParameters { override fun impl(): org.jetbrains.kotlin.descriptors.ClassDescriptor = impl + override fun annotations(): Annotations = KotlinAnnotations(impl().annotations) override val unsubstitutedMemberScope: MemberScope get() = KotlinMemberScope { impl.unsubstitutedMemberScope } + override val staticScope: MemberScope get() = KotlinMemberScope { impl.staticScope } + override val unsubstitutedInnerClassesScope: MemberScope get() = KotlinMemberScope { impl.unsubstitutedInnerClassesScope } override val constructors: Collection get() = impl().constructors.map { it.model() } + override val companionObjectDescriptor: ClassDescriptor? get() = impl().companionObjectDescriptor?.model() + override val kind: ClassDescriptor.ClassKind get() = when (impl().kind) { @@ -38,28 +43,40 @@ class KotlinClassDescriptor(val impl: org.jetbrains.kotlin.descriptors.ClassDesc ClassKind.ANNOTATION_CLASS -> ClassDescriptor.ClassKind.ANNOTATION_CLASS ClassKind.OBJECT -> ClassDescriptor.ClassKind.OBJECT } + override val isCompanionObject: Boolean get() = impl().isCompanionObject + override val isData: Boolean get() = impl().isData + override val isInline: Boolean get() = impl().isInline + override val isFun: Boolean get() = impl().isFun + override val isValue: Boolean get() = impl().isValue + override val isEnumEntry: Boolean get() = impl().kind == ClassKind.ENUM_ENTRY + override val thisAsReceiverParameter: ReceiverParameterDescriptor get() = impl().thisAsReceiverParameter.model() + override val unsubstitutedPrimaryConstructor: ConstructorDescriptor? get() = impl().unsubstitutedPrimaryConstructor?.model() + override val sealedSubclasses: Collection get() = impl().sealedSubclasses.map { it.model() } + override val superTypes: Collection get() = impl.defaultType.constructor.supertypes.map { KotlinType(it) } + override val isInner: Boolean get() = impl.isInner + override val declaredTypeParameters: List get() = impl().declaredTypeParameters.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinClassifierDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinClassifierDescriptor.kt index af275637..78a43f79 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinClassifierDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinClassifierDescriptor.kt @@ -10,6 +10,7 @@ fun interface KotlinClassifierDescriptor : ClassifierDescriptor { override val typeConstructor: TypeConstructor get() = KotlinTypeConstructor { impl().typeConstructor } + override val defaultType: Type get() = KotlinType(impl().defaultType) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinDeclarationDescriptorWithVisibility.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinDeclarationDescriptorWithVisibility.kt index 362e28f5..1ced9568 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinDeclarationDescriptorWithVisibility.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinDeclarationDescriptorWithVisibility.kt @@ -6,6 +6,7 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.descriptor fun interface KotlinDeclarationDescriptorWithVisibility : DeclarationDescriptorWithVisibility, KotlinDeclarationDescriptor { override fun impl(): org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility + override val visibility: Visibility get() = KotlinVisibility { impl().visibility.delegate } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinExpressionValueArgument.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinExpressionValueArgument.kt index 847f25d2..97f3c7ff 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinExpressionValueArgument.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinExpressionValueArgument.kt @@ -16,8 +16,10 @@ open class KotlinExpressionValueArgument( ExpressionResolvedValueArgument, KotlinResolvedValueArgument(impl) { override fun impl(): org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument = impl + override val argumentExpression: Expression? get() = impl().valueArgument?.getArgumentExpression()?.model() + override val isSpread: Boolean get() = impl().valueArgument?.getSpreadElement() != null diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinFunctionDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinFunctionDescriptor.kt index 7930364a..0808c2f7 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinFunctionDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinFunctionDescriptor.kt @@ -18,14 +18,19 @@ abstract class KotlinFunctionDescriptor( Kind.DELEGATION -> CallableMemberDescriptor.Kind.DELEGATION Kind.SYNTHESIZED -> CallableMemberDescriptor.Kind.SYNTHESIZED } + override val isOperator: Boolean get() = impl().isOperator + override val isInfix: Boolean get() = impl().isInfix + override val isInline: Boolean get() = impl().isInline + override val isTailrec: Boolean get() = impl().isTailrec + override val isSuspend: Boolean get() = impl().isSuspend } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinNamed.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinNamed.kt index 25ec4bd7..dbe6937d 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinNamed.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinNamed.kt @@ -5,6 +5,7 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.elements.N fun interface KotlinNamed : Named { fun impl(): org.jetbrains.kotlin.descriptors.Named + override val name: Name get() = Name(impl().name.asString()) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinPropertyAccessorDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinPropertyAccessorDescriptor.kt index dd427edc..6b8ef9c0 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinPropertyAccessorDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinPropertyAccessorDescriptor.kt @@ -8,8 +8,10 @@ class KotlinPropertyAccessorDescriptor( override val impl: org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor ) : PropertyAccessorDescriptor, KotlinVariableAccessorDescriptor(impl) { override fun impl(): org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor = impl + override val overriddenDescriptors: Collection get() = impl().overriddenDescriptors.map { it.model() } + override val correspondingVariable: VariableDescriptorWithAccessors get() = impl().correspondingVariable.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinPropertyDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinPropertyDescriptor.kt index 2202dc47..97701a13 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinPropertyDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinPropertyDescriptor.kt @@ -10,12 +10,16 @@ class KotlinPropertyDescriptor( ) : PropertyDescriptor, KotlinVariableDescriptorWithAccessors(impl), KotlinCallableMemberDescriptor { override fun impl(): org.jetbrains.kotlin.descriptors.PropertyDescriptor = impl + override val isSetterProjectedOut: Boolean get() = impl().isSetterProjectedOut + override val accessors: List get() = impl().accessors.map { it.model() } + override val backingField: FieldDescriptor? get() = impl().backingField?.let { KotlinFieldDescriptor { it } } + override val delegateField: FieldDescriptor? get() = impl().delegateField?.let { KotlinFieldDescriptor { it } } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinReceiverValue.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinReceiverValue.kt index 09baae35..52a2bdc0 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinReceiverValue.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinReceiverValue.kt @@ -8,8 +8,10 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ClassValueReceiver class KotlinReceiverValue(val impl: org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue) : ReceiverValue { fun impl(): org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue = impl + override val type: Type get() = KotlinType(impl().type) + override val isClassReceiver: Boolean get() = impl is ClassValueReceiver } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinResolvedValueArgument.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinResolvedValueArgument.kt index cf0e51d0..aa082106 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinResolvedValueArgument.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinResolvedValueArgument.kt @@ -7,6 +7,7 @@ open class KotlinResolvedValueArgument( open val impl: org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument ) : ResolvedValueArgument { open fun impl(): org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument = impl + override val arguments: List get() = impl().arguments.map { KotlinValueArgument(it) } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinSimpleFunctionDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinSimpleFunctionDescriptor.kt index a4778a45..7dd3cb27 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinSimpleFunctionDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinSimpleFunctionDescriptor.kt @@ -18,14 +18,19 @@ class KotlinSimpleFunctionDescriptor( Kind.DELEGATION -> CallableMemberDescriptor.Kind.DELEGATION Kind.SYNTHESIZED -> CallableMemberDescriptor.Kind.SYNTHESIZED } + override val isOperator: Boolean get() = impl().isOperator + override val isInfix: Boolean get() = impl().isInfix + override val isInline: Boolean get() = impl().isInline + override val isTailrec: Boolean get() = impl().isTailrec + override val isSuspend: Boolean get() = impl().isSuspend } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeAliasDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeAliasDescriptor.kt index 08dc5c64..67edde60 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeAliasDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeAliasDescriptor.kt @@ -10,12 +10,16 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.kotlin.types.Kotli class KotlinTypeAliasDescriptor(val impl: org.jetbrains.kotlin.descriptors.TypeAliasDescriptor) : TypeAliasDescriptor, KotlinClassifierDescriptorWithTypeParameters { override fun impl(): org.jetbrains.kotlin.descriptors.TypeAliasDescriptor = impl + override val underlyingType: Type get() = KotlinType(impl().underlyingType) + override val expandedType: Type get() = KotlinType(impl().expandedType) + override val classDescriptor: ClassDescriptor? get() = impl().classDescriptor?.model() + override val constructors: Collection get() = impl().constructors.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeConstructor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeConstructor.kt index 7c5469a1..e2fa033a 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeConstructor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeConstructor.kt @@ -13,12 +13,16 @@ fun interface KotlinTypeConstructor : TypeConstructor { override val parameters: List get() = impl().parameters.map { it.model() } + override val supertypes: Collection get() = impl().supertypes.map { KotlinType(it) } + override val isFinal: Boolean get() = impl().isFinal + override val isDenotable: Boolean get() = impl().isDenotable + override val declarationDescriptor: ClassifierDescriptor? get() = impl().declarationDescriptor?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeParameterDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeParameterDescriptor.kt index 6a8514e5..2e2bc7b5 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeParameterDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinTypeParameterDescriptor.kt @@ -14,6 +14,7 @@ fun interface KotlinTypeParameterDescriptor : TypeParameterDescriptor, KotlinCla override val isReified: Boolean get() = impl().isReified + override val variance: Variance get() = when (impl().variance) { @@ -21,10 +22,13 @@ fun interface KotlinTypeParameterDescriptor : TypeParameterDescriptor, KotlinCla IN_VARIANCE -> Variance.In OUT_VARIANCE -> Variance.Out } + override val upperBounds: List get() = impl().upperBounds.map { KotlinType(it) } + override val index: Int get() = impl().index + override val isCapturedFromOuterDeclaration: Boolean get() = impl().isCapturedFromOuterDeclaration } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueArgument.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueArgument.kt index 33c412b0..ba548380 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueArgument.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueArgument.kt @@ -19,6 +19,7 @@ class KotlinValueArgument(val impl: org.jetbrains.kotlin.psi.ValueArgument) : override val argumentExpression: Expression? get() = impl.getArgumentExpression()?.model() + override val isSpread: Boolean get() = impl.getSpreadElement() != null diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueDescriptor.kt index 5cfdeb94..53370e17 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueDescriptor.kt @@ -6,6 +6,7 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.kotlin.types.Kotli fun interface KotlinValueDescriptor : ValueDescriptor, KotlinCallableDescriptor { override fun impl(): org.jetbrains.kotlin.descriptors.ValueDescriptor + override val type: Type get() = KotlinType(impl().type) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueParameterDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueParameterDescriptor.kt index 8c6baf90..31b370c9 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueParameterDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinValueParameterDescriptor.kt @@ -12,16 +12,21 @@ class KotlinValueParameterDescriptor( override val impl: org.jetbrains.kotlin.descriptors.ValueParameterDescriptor ) : ValueParameterDescriptor, KotlinVariableDescriptor(impl), KotlinParameterDescriptor { override fun impl(): org.jetbrains.kotlin.descriptors.ValueParameterDescriptor = impl + override val index: Int get() = impl().index + override val isCrossinline: Boolean get() = impl().isCrossinline + override val isNoinline: Boolean get() = impl().isNoinline + override val varargElementType: Type? get() = impl().varargElementType?.let { KotlinType(it) } override fun declaresDefaultValue(): Boolean = impl().declaresDefaultValue() + override val defaultValue: Expression? get() = (impl.source.getPsi() as? KtParameter)?.defaultValue?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableAccessorDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableAccessorDescriptor.kt index 29fd5c47..8b332311 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableAccessorDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableAccessorDescriptor.kt @@ -8,6 +8,7 @@ abstract class KotlinVariableAccessorDescriptor( override val impl: org.jetbrains.kotlin.descriptors.VariableAccessorDescriptor ) : VariableAccessorDescriptor, KotlinFunctionDescriptor(impl) { override fun impl(): org.jetbrains.kotlin.descriptors.VariableAccessorDescriptor = impl + override val correspondingVariable: VariableDescriptorWithAccessors get() = impl().correspondingVariable.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableDescriptor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableDescriptor.kt index 54edd367..166eab3d 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableDescriptor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableDescriptor.kt @@ -10,8 +10,10 @@ abstract class KotlinVariableDescriptor( override val isVar: Boolean get() = impl().isVar + override val isConst: Boolean get() = impl().isConst + override val isLateInit: Boolean get() = impl().isLateInit } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableDescriptorWithAccessors.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableDescriptorWithAccessors.kt index c397d5d0..22644ccb 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableDescriptorWithAccessors.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVariableDescriptorWithAccessors.kt @@ -9,10 +9,13 @@ abstract class KotlinVariableDescriptorWithAccessors( ) : VariableDescriptorWithAccessors, KotlinVariableDescriptor(impl) { override fun impl(): org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors = impl + override val getter: VariableAccessorDescriptor? get() = impl().getter?.model() + override val isDelegated: Boolean get() = impl().isDelegated + override val setter: VariableAccessorDescriptor? get() = impl().setter?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVisibility.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVisibility.kt index 5abba2d8..75c5af68 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVisibility.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/descriptors/KotlinVisibility.kt @@ -4,8 +4,10 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.context.descriptor fun interface KotlinVisibility : Visibility { fun impl(): org.jetbrains.kotlin.descriptors.Visibility + override val isPublicAPI: Boolean get() = impl().isPublicAPI + override val name: String get() = impl().name } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnnotation.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnnotation.kt index a056161f..395d1996 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnnotation.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnnotation.kt @@ -8,8 +8,10 @@ import org.jetbrains.kotlin.psi.KtAnnotation class KotlinAnnotation(val impl: KtAnnotation) : Annotation, KotlinElement { override fun impl(): KtAnnotation = impl + override val entries: List get() = impl().entries.map { it.model() } + override val useSiteTarget: AnnotationUseSiteTarget? get() = impl().useSiteTarget?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnnotationEntry.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnnotationEntry.kt index 813bcaa7..2a9efb98 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnnotationEntry.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnnotationEntry.kt @@ -9,10 +9,13 @@ import org.jetbrains.kotlin.psi.KtAnnotationEntry class KotlinAnnotationEntry(val impl: KtAnnotationEntry) : AnnotationEntry, KotlinCallElement { override fun impl(): KtAnnotationEntry = impl + override val typeReference: TypeReference? get() = impl().typeReference?.model() + override val useSiteTarget: AnnotationUseSiteTarget? get() = impl().useSiteTarget?.model() + override val shortName: Name? get() = impl().shortName?.asString()?.let { Name(it) } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnonymousInitializer.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnonymousInitializer.kt index 0eec5e1d..0dee9d58 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnonymousInitializer.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAnonymousInitializer.kt @@ -8,8 +8,10 @@ import org.jetbrains.kotlin.psi.KtAnonymousInitializer fun interface KotlinAnonymousInitializer : AnonymousInitializer, KotlinDeclaration { override fun impl(): KtAnonymousInitializer + override val containingDeclaration: Declaration get() = impl().containingDeclaration.model() + override val body: Expression? get() = impl().body?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinArrayAccessExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinArrayAccessExpression.kt index d00c83b6..6da8c8a2 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinArrayAccessExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinArrayAccessExpression.kt @@ -8,8 +8,10 @@ import org.jetbrains.kotlin.psi.KtArrayAccessExpression class KotlinArrayAccessExpression(val impl: KtArrayAccessExpression) : ArrayAccessExpression, KotlinReferenceExpression { override fun impl(): KtArrayAccessExpression = impl + override val arrayExpression: Expression? get() = impl().arrayExpression?.model() + override val indexExpressions: List get() = impl().indexExpressions.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAssignmentExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAssignmentExpression.kt index 20351d66..dcb619f5 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAssignmentExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinAssignmentExpression.kt @@ -9,12 +9,16 @@ import org.jetbrains.kotlin.psi.KtBinaryExpression class KotlinAssignmentExpression(val impl: KtBinaryExpression) : AssignmentExpression, KotlinOperationExpression { override fun impl(): KtBinaryExpression = impl + override val operationToken: String get() = (impl().operationToken as KtSingleValueToken).value + override val operationTokenRpr: String get() = impl().operationToken.toString() + override val left: Expression? get() = impl().left?.model() + override val right: Expression? get() = impl().right?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinBinaryExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinBinaryExpression.kt index 0859d284..b5aa65d0 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinBinaryExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinBinaryExpression.kt @@ -9,12 +9,16 @@ import org.jetbrains.kotlin.psi.KtBinaryExpression class KotlinBinaryExpression(val impl: KtBinaryExpression) : BinaryExpression, KotlinOperationExpression { override fun impl(): KtBinaryExpression = impl + override val operationToken: String get() = (impl().operationToken as KtSingleValueToken).value + override val operationTokenRpr: String get() = impl().operationToken.toString() + override val left: Expression? get() = impl().left?.model() + override val right: Expression? get() = impl().right?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinBlockExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinBlockExpression.kt index 866e333a..62c31e55 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinBlockExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinBlockExpression.kt @@ -8,9 +8,12 @@ import org.jetbrains.kotlin.psi.KtBlockExpression class KotlinBlockExpression(val impl: KtBlockExpression) : BlockExpression, KotlinElement, KotlinExpression { override fun impl(): KtBlockExpression = impl + override val firstStatement: Expression? get() = impl().firstStatement?.model() + override val statements: List get() = impl().statements.map { it.model() } + override val implicitReturnFromLast: Boolean = true } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCallElement.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCallElement.kt index efb8d439..b5914bf4 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCallElement.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCallElement.kt @@ -11,12 +11,16 @@ import org.jetbrains.kotlin.psi.KtCallElement fun interface KotlinCallElement : CallElement, KotlinElement { override fun impl(): KtCallElement + override val calleeExpression: Expression? get() = impl().calleeExpression?.model() + override val valueArguments: List get() = impl().valueArguments.map { KotlinValueArgument(it) } + override val lambdaArguments: List get() = impl().lambdaArguments.map { it.model() } + override val typeArguments: List get() = TODO("Not yet implemented") } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCallableDeclaration.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCallableDeclaration.kt index ad06dc35..9c15df79 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCallableDeclaration.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCallableDeclaration.kt @@ -10,12 +10,16 @@ import org.jetbrains.kotlin.psi.KtCallableDeclaration fun interface KotlinCallableDeclaration : CallableDeclaration, KotlinNamedDeclaration, KotlinTypeParameterListOwner { override fun impl(): KtCallableDeclaration + override val valueParameterList: ParameterList? get() = impl().valueParameterList?.model() + override val valueParameters: List get() = impl().valueParameters.map { it.model() } + override val receiverTypeReference: TypeReference? get() = impl().receiverTypeReference?.model() + override val typeReference: TypeReference? get() = impl().typeReference?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCatchClause.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCatchClause.kt index 5400b722..b040675e 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCatchClause.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCatchClause.kt @@ -9,10 +9,13 @@ import org.jetbrains.kotlin.psi.KtCatchClause class KotlinCatchClause(val impl: KtCatchClause) : CatchClause, KotlinElement { override fun impl(): KtCatchClause = impl + override val parameterList: ParameterList? get() = impl().parameterList?.model() + override val catchParameter: Parameter? get() = impl().catchParameter?.model() + override val catchBody: Expression? get() = impl().catchBody?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinClassBody.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinClassBody.kt index d4a3ea1c..e05c0d61 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinClassBody.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinClassBody.kt @@ -12,14 +12,19 @@ import org.jetbrains.kotlin.psi.KtClassBody class KotlinClassBody(val impl: KtClassBody) : ClassBody, KotlinDeclarationContainer, KotlinElement { override fun impl(): KtClassBody = impl + override val anonymousInitializers: List get() = impl().anonymousInitializers.map { it.model() } + override val properties: List get() = impl().properties.map { it.model() } + override val functions: List get() = impl().functions.map { it.model() } + override val enumEntries: List get() = impl().enumEntries.map { it.model() } + override val allCompanionObjects: List get() = impl().allCompanionObjects.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCompilerMessageSourceLocation.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCompilerMessageSourceLocation.kt index 59160149..df8fae46 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCompilerMessageSourceLocation.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinCompilerMessageSourceLocation.kt @@ -7,14 +7,19 @@ class KotlinCompilerMessageSourceLocation( ) : CompilerMessageSourceLocation { override val column: Int get() = impl.column + override val columnEnd: Int get() = impl.columnEnd + override val line: Int get() = impl.line + override val lineContent: String? get() = impl.lineContent + override val lineEnd: Int get() = impl.lineEnd + override val path: String get() = impl.path } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructor.kt index effb4f43..2527875e 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructor.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtConstructor fun interface KotlinConstructor> : Constructor, KotlinFunction { override fun impl(): KtConstructor<*> + override fun getContainingClassOrObject(): ClassOrObject = impl().getContainingClassOrObject().model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorCalleeExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorCalleeExpression.kt index 6dd7c0de..39cebf44 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorCalleeExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorCalleeExpression.kt @@ -9,8 +9,10 @@ import org.jetbrains.kotlin.psi.KtConstructorCalleeExpression class KotlinConstructorCalleeExpression(override val impl: KtConstructorCalleeExpression) : ConstructorCalleeExpression, KotlinDefaultExpression(impl) { override fun impl(): KtConstructorCalleeExpression = impl + override val typeReference: TypeReference? get() = impl().typeReference?.model() + override val constructorReferenceExpression: SimpleNameExpression? get() = impl().constructorReferenceExpression?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorDelegationCall.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorDelegationCall.kt index 6c1f11f2..fe821da8 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorDelegationCall.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorDelegationCall.kt @@ -6,8 +6,10 @@ import org.jetbrains.kotlin.psi.KtConstructorDelegationCall class KotlinConstructorDelegationCall(val impl: KtConstructorDelegationCall) : ConstructorDelegationCall, KotlinElement, KotlinCallElement { override fun impl(): KtConstructorDelegationCall = impl + override val isImplicit: Boolean get() = impl().isImplicit + override val isCallToThis: Boolean get() = impl().isCallToThis } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorDelegationReferenceExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorDelegationReferenceExpression.kt index 341c73c2..91e6c909 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorDelegationReferenceExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinConstructorDelegationReferenceExpression.kt @@ -7,6 +7,7 @@ class KotlinConstructorDelegationReferenceExpression( val impl: KtConstructorDelegationReferenceExpression ) : ConstructorDelegationReferenceExpression, KotlinExpression, KotlinReferenceExpression { override fun impl(): KtConstructorDelegationReferenceExpression = impl + override val isThis: Boolean get() = impl().isThis } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclaration.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclaration.kt index 04b07d59..33b77345 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclaration.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclaration.kt @@ -10,8 +10,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents fun interface KotlinDeclaration : Declaration, KotlinExpression, KotlinModifierListOwner { override fun impl(): KtDeclaration + override val name: String? get() = impl().name + override val parents: List get() = impl() diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclarationContainer.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclarationContainer.kt index 420457a4..03be6bc5 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclarationContainer.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclarationContainer.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtDeclarationContainer fun interface KotlinDeclarationContainer : DeclarationContainer { fun impl(): KtDeclarationContainer + override val declarations: List get() = impl().declarations.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclarationWithBody.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclarationWithBody.kt index 16841362..05740d94 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclarationWithBody.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDeclarationWithBody.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.psi.KtDeclarationWithBody fun interface KotlinDeclarationWithBody : DeclarationWithBody, KotlinDeclaration { override fun impl(): KtDeclarationWithBody + override val bodyExpression: Expression? get() = impl().bodyExpression?.model() diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDelegatedSuperTypeEntry.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDelegatedSuperTypeEntry.kt index 4d63aac1..a199bd0b 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDelegatedSuperTypeEntry.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDelegatedSuperTypeEntry.kt @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.psi.KtDelegatedSuperTypeEntry class KotlinDelegatedSuperTypeEntry(val impl: KtDelegatedSuperTypeEntry) : DelegatedSuperTypeEntry, KotlinSuperTypeListEntry { override fun impl(): KtDelegatedSuperTypeEntry = impl + override val delegateExpression: Expression? get() = impl().delegateExpression?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDestructuringDeclaration.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDestructuringDeclaration.kt index 88a09df4..412f1e73 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDestructuringDeclaration.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDestructuringDeclaration.kt @@ -8,8 +8,10 @@ import org.jetbrains.kotlin.psi.KtDestructuringDeclaration class KotlinDestructuringDeclaration(val impl: KtDestructuringDeclaration) : DestructuringDeclaration, KotlinDeclarationWithInitializer { override fun impl(): KtDestructuringDeclaration = impl + override val entries: List get() = impl().entries.map { it.model() } + override val isVar: Boolean get() = impl().isVar } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDestructuringDeclarationEntry.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDestructuringDeclarationEntry.kt index c9fd74fe..0bae7ae8 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDestructuringDeclarationEntry.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDestructuringDeclarationEntry.kt @@ -6,6 +6,7 @@ import org.jetbrains.kotlin.psi.KtDestructuringDeclarationEntry class KotlinDestructuringDeclarationEntry(val impl: KtDestructuringDeclarationEntry) : DestructuringDeclarationEntry, KotlinVariableDeclaration { override fun impl(): KtDestructuringDeclarationEntry = impl + override val isVar: Boolean get() = impl().isVar } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDoubleColonExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDoubleColonExpression.kt index 3600b74e..d2e022f2 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDoubleColonExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinDoubleColonExpression.kt @@ -7,10 +7,13 @@ import org.jetbrains.kotlin.psi.KtDoubleColonExpression fun interface KotlinDoubleColonExpression : DoubleColonExpression, KotlinExpression { override fun impl(): KtDoubleColonExpression + override val receiverExpression: Expression? get() = impl().receiverExpression?.model() + override val hasQuestionMarks: Boolean get() = impl().hasQuestionMarks + override val isEmptyLHS: Boolean get() = impl().isEmptyLHS } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinEnumEntry.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinEnumEntry.kt index 0ada19b3..b53cbc05 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinEnumEntry.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinEnumEntry.kt @@ -5,5 +5,6 @@ import org.jetbrains.kotlin.psi.KtEnumEntry class KotlinEnumEntry(override val impl: KtEnumEntry) : EnumEntry, KotlinClass(impl) { override fun impl(): KtEnumEntry = impl + override fun hasInitializer(): Boolean = impl().hasInitializer() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpression.kt index be46d1a9..4439cb1f 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpression.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.utils.IDEAPluginsCompatibilityAPI @OptIn(IDEAPluginsCompatibilityAPI::class) fun interface KotlinExpression : Expression, KotlinElement { override fun impl(): KtExpression + override fun type(context: ResolutionContext): Type? = if (context is KotlinResolutionContext) impl().getType(context.bindingContext)?.let { KotlinType(it) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionValueArgument.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionValueArgument.kt index e6e081ae..6ac95b22 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionValueArgument.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionValueArgument.kt @@ -17,6 +17,7 @@ open class KotlinExpressionValueArgument(open val impl: org.jetbrains.kotlin.psi override val argumentExpression: Expression? get() = impl().getArgumentExpression()?.model() + override val isSpread: Boolean get() = impl().isSpread } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionValueArgumentName.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionValueArgumentName.kt index 416396eb..f2f9b0fa 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionValueArgumentName.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionValueArgumentName.kt @@ -8,8 +8,10 @@ import org.jetbrains.kotlin.psi.KtValueArgumentName fun interface KotlinExpressionValueArgumentName : ValueArgumentName { fun impl(): KtValueArgumentName + override val asName: Name get() = Name(impl().asName.asString()) + override val referenceExpression: SimpleNameExpression? get() = impl().referenceExpression.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionWithLabel.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionWithLabel.kt index ed8064f8..2023f7d8 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionWithLabel.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinExpressionWithLabel.kt @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.psi.KtExpressionWithLabel fun interface KotlinExpressionWithLabel : ExpressionWithLabel, KotlinExpression { override fun impl(): KtExpressionWithLabel + override fun getTargetLabel(): SimpleNameExpression? = impl().getTargetLabel()?.model() override fun getLabelName(): String? = impl().getLabelName() diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFinallySection.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFinallySection.kt index 111f5912..05b7d4cb 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFinallySection.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFinallySection.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtFinallySection class KotlinFinallySection(val impl: KtFinallySection) : FinallySection, KotlinElement { override fun impl(): KtFinallySection = impl + override val finalExpression: BlockExpression get() = impl.finalExpression.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinForExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinForExpression.kt index 1db308c8..cb311630 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinForExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinForExpression.kt @@ -9,10 +9,13 @@ import org.jetbrains.kotlin.psi.KtForExpression class KotlinForExpression(val impl: KtForExpression) : ForExpression, KotlinLoopExpression { override fun impl(): KtForExpression = impl + override val loopParameter: Parameter? get() = impl().loopParameter?.model() + override val destructuringDeclaration: DestructuringDeclaration? get() = impl().destructuringDeclaration?.model() + override val loopRange: Expression? get() = impl().loopRange?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFunction.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFunction.kt index c5a5ba56..47c52b65 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFunction.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFunction.kt @@ -7,8 +7,10 @@ import org.jetbrains.kotlin.psi.KtFunction interface KotlinFunction : Function, KotlinDeclarationWithBody, KotlinCallableDeclaration { override fun impl(): KtFunction + override val isLocal: Boolean get() = impl().isLocal + override val valueParameters: List get() = impl().valueParameters.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFunctionLiteral.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFunctionLiteral.kt index 269016ed..6b395fb3 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFunctionLiteral.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinFunctionLiteral.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtFunctionLiteral class KotlinFunctionLiteral(val impl: KtFunctionLiteral) : FunctionLiteral, KotlinFunction { override fun impl(): KtFunctionLiteral = impl + override fun hasParameterSpecification(): Boolean = impl().hasParameterSpecification() override val bodyExpression: Expression? diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinIfExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinIfExpression.kt index 9d13b9e0..4b4bf292 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinIfExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinIfExpression.kt @@ -7,10 +7,13 @@ import org.jetbrains.kotlin.psi.KtIfExpression class KotlinIfExpression(val impl: KtIfExpression) : IfExpression, KotlinExpression { override fun impl(): KtIfExpression = impl + override val condition: Expression? get() = impl().condition?.model() + override val thenExpression: Expression? get() = impl().then?.model() + override val elseExpression: Expression? get() = impl().`else`?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinIsExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinIsExpression.kt index 40066f8b..c27234c4 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinIsExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinIsExpression.kt @@ -10,12 +10,16 @@ import org.jetbrains.kotlin.psi.KtIsExpression class KotlinIsExpression(val impl: KtIsExpression) : IsExpression, KotlinExpression, KotlinOperationExpression { override fun impl(): KtIsExpression = impl + override val leftHandSide: Expression get() = impl().leftHandSide.model() + override val typeReference: TypeReference? get() = impl().typeReference?.model() + override val operationReference: SimpleNameExpression get() = impl().operationReference.model() + override val isNegated: Boolean get() = impl().isNegated } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLabeledExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLabeledExpression.kt index 20320af3..5a5054fe 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLabeledExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLabeledExpression.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtLabeledExpression fun interface KotlinLabeledExpression : LabeledExpression, KotlinExpressionWithLabel { override fun impl(): KtLabeledExpression + override val baseExpression: Expression? get() = impl().baseExpression?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLambdaArgument.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLambdaArgument.kt index f90d1ed8..50f13a22 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLambdaArgument.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLambdaArgument.kt @@ -8,5 +8,6 @@ import org.jetbrains.kotlin.psi.KtLambdaArgument open class KotlinLambdaArgument(override val impl: KtLambdaArgument) : LambdaArgument, KotlinExpressionValueArgument(impl) { override fun impl(): KtLambdaArgument = impl + override fun getLambdaExpression(): LambdaExpression? = impl().getLambdaExpression()?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLambdaExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLambdaExpression.kt index 945bc59b..58acf75a 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLambdaExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLambdaExpression.kt @@ -9,10 +9,13 @@ import org.jetbrains.kotlin.psi.KtLambdaExpression class KotlinLambdaExpression(val impl: KtLambdaExpression) : LambdaExpression, KotlinExpression { override fun impl(): KtLambdaExpression = impl + override val functionLiteral: FunctionLiteral get() = impl().functionLiteral.model() + override val valueParameters: List get() = impl().valueParameters.map { it.model() } + override val bodyExpression: BlockExpression? get() = impl().bodyExpression?.model() diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLoopExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLoopExpression.kt index c88675f1..3d93611a 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLoopExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinLoopExpression.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtLoopExpression fun interface KotlinLoopExpression : LoopExpression, KotlinExpression { override fun impl(): KtLoopExpression + override val body: Expression? get() = impl().body?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinModifierList.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinModifierList.kt index 94f672be..1e80b116 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinModifierList.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinModifierList.kt @@ -8,8 +8,10 @@ import org.jetbrains.kotlin.psi.KtModifierList class KotlinModifierList(val impl: KtModifierList) : ModifierList, KotlinAnnotationsContainer { override fun impl(): KtModifierList = impl + override val annotations: List get() = impl().annotations.map { it.model() } + override val annotationEntries: List get() = impl().annotationEntries.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinNamedDeclaration.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinNamedDeclaration.kt index 48f05ee6..48c13bbe 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinNamedDeclaration.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinNamedDeclaration.kt @@ -7,10 +7,13 @@ import org.jetbrains.kotlin.psi.KtNamedDeclaration fun interface KotlinNamedDeclaration : NamedDeclaration, KotlinDeclaration { override fun impl(): KtNamedDeclaration + override val nameAsName: Name? get() = impl().nameAsName?.let { Name(it.asString()) } + override val nameAsSafeName: Name get() = Name(impl().nameAsSafeName.asString()) + override val fqName: FqName? get() = impl().fqName?.let { FqName(it.asString()) } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinObjectLiteralExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinObjectLiteralExpression.kt index ee5d7ca3..b90bdc8e 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinObjectLiteralExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinObjectLiteralExpression.kt @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.psi.KtObjectLiteralExpression class KotlinObjectLiteralExpression(val impl: KtObjectLiteralExpression) : ObjectLiteralExpression, KotlinExpression { override fun impl(): KtObjectLiteralExpression = impl + override val objectDeclaration: ObjectDeclaration get() = impl().objectDeclaration.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinOperationExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinOperationExpression.kt index 640e1bd8..86b52849 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinOperationExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinOperationExpression.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtOperationExpression fun interface KotlinOperationExpression : OperationExpression, KotlinExpression { override fun impl(): KtOperationExpression + override val operationReference: SimpleNameExpression get() = impl().operationReference.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinOperationReferenceExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinOperationReferenceExpression.kt index 1cfd9d9a..0f63f2dd 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinOperationReferenceExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinOperationReferenceExpression.kt @@ -6,5 +6,6 @@ import org.jetbrains.kotlin.psi.KtOperationReferenceExpression class KotlinOperationReferenceExpression(val impl: KtOperationReferenceExpression) : OperationReferenceExpression, KotlinSimpleNameExpression { override fun impl(): KtOperationReferenceExpression = impl + override fun isConventionOperator(): Boolean = impl().isConventionOperator() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinParameter.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinParameter.kt index 06ab5947..b0b37d26 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinParameter.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinParameter.kt @@ -9,12 +9,15 @@ import org.jetbrains.kotlin.psi.KtParameter class KotlinParameter(val impl: KtParameter) : Parameter, KotlinCallableDeclaration { override fun impl(): KtParameter = impl + override fun hasDefaultValue(): Boolean = impl().hasDefaultValue() override val defaultValue: Expression? get() = impl().defaultValue?.model() + override val isMutable: Boolean get() = impl().isMutable + override val isVarArg: Boolean get() = impl().isVarArg @@ -22,10 +25,13 @@ class KotlinParameter(val impl: KtParameter) : Parameter, KotlinCallableDeclarat override val destructuringDeclaration: DestructuringDeclaration? get() = impl().destructuringDeclaration?.model() + override val isLoopParameter: Boolean get() = impl().isLoopParameter + override val isCatchParameter: Boolean get() = impl().isCatchParameter + override val ownerFunction: DeclarationWithBody? get() = impl().ownerFunction?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProjectionKind.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProjectionKind.kt index 6e3f4f25..f1a87445 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProjectionKind.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProjectionKind.kt @@ -4,5 +4,5 @@ enum class KotlinProjectionKind { IN, OUT, STAR, - NONE + NONE, } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProperty.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProperty.kt index 02157d3e..6f74035e 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProperty.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinProperty.kt @@ -9,16 +9,22 @@ import org.jetbrains.kotlin.psi.KtProperty class KotlinProperty(val impl: KtProperty) : Property, KotlinVariableDeclaration { override fun impl(): KtProperty = impl + override val isLocal: Boolean get() = impl().isLocal + override val isMember: Boolean get() = impl().isMember + override val isTopLevel: Boolean get() = impl().isTopLevel + override val accessors: List get() = impl().accessors.map { it.model() } + override val getter: PropertyAccessor? get() = impl().getter?.model() + override val setter: PropertyAccessor? get() = impl().setter?.model() diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPropertyAccessor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPropertyAccessor.kt index 44db7ccb..bb47996f 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPropertyAccessor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPropertyAccessor.kt @@ -14,16 +14,22 @@ class KotlinPropertyAccessor(val impl: KtPropertyAccessor) : KotlinModifierListOwner, KotlinDeclarationWithInitializer { override fun impl(): KtPropertyAccessor = impl + override val isSetter: Boolean get() = impl().isSetter + override val isGetter: Boolean get() = impl().isGetter + override val parameterList: ParameterList? get() = impl().parameterList?.model() + override val parameter: Parameter? get() = impl().parameter?.model() + override val returnTypeReference: TypeReference? get() = impl().returnTypeReference?.model() + override val property: Property get() = impl().property.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPropertyDelegate.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPropertyDelegate.kt index 177f15de..cd32ced0 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPropertyDelegate.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPropertyDelegate.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtPropertyDelegate class KotlinPropertyDelegate(val impl: KtPropertyDelegate) : PropertyDelegate, KotlinElement { override fun impl(): KtPropertyDelegate = impl + override val expression: Expression? get() = impl().expression?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPureClassOrObject.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPureClassOrObject.kt index d82cb06b..5f53a48c 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPureClassOrObject.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinPureClassOrObject.kt @@ -17,10 +17,13 @@ fun interface KotlinPureClassOrObject : PureClassOrObject, KotlinDeclarationCont override val name: String? get() = impl().name + override val isLocal: Boolean get() = impl().isLocal + override val superTypeListEntries: List get() = impl().superTypeListEntries.map { it.model() } + override val companionObjects: List get() = impl().companionObjects.map { it.model() } @@ -30,14 +33,19 @@ fun interface KotlinPureClassOrObject : PureClassOrObject, KotlinDeclarationCont override val primaryConstructor: PrimaryConstructor? get() = impl().primaryConstructor?.model() + override val primaryConstructorModifierList: ModifierList? get() = impl().primaryConstructorModifierList?.model() + override val primaryConstructorParameters: List get() = impl().primaryConstructorParameters.map { it.model() } + override val secondaryConstructors: List get() = impl().secondaryConstructors.map { it.model() } + override val body: ClassBody? get() = impl().body?.model() + override val psiOrParent: Element get() = impl().psiOrParent.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinQualifiedExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinQualifiedExpression.kt index 31d24ece..3ae50bef 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinQualifiedExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinQualifiedExpression.kt @@ -7,8 +7,10 @@ import org.jetbrains.kotlin.psi.KtQualifiedExpression fun interface KotlinQualifiedExpression : QualifiedExpression, KotlinExpression { override fun impl(): KtQualifiedExpression + override val receiverExpression: Expression get() = impl().receiverExpression.model() + override val selectorExpression: Expression? get() = impl().selectorExpression?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinReturnExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinReturnExpression.kt index 035c9f63..21459200 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinReturnExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinReturnExpression.kt @@ -9,8 +9,10 @@ import org.jetbrains.kotlin.psi.KtReturnExpression class KotlinReturnExpression(val impl: KtReturnExpression) : ReturnExpression, KotlinExpressionWithLabel { override fun impl(): KtReturnExpression = impl + override val returnedExpression: Expression? get() = impl().returnedExpression?.model() + override val labeledExpression: Expression? get() = (impl().labeledExpression as? KtElement)?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSecondaryConstructor.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSecondaryConstructor.kt index fddf044b..245d2fb1 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSecondaryConstructor.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSecondaryConstructor.kt @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.psi.KtSecondaryConstructor class KotlinSecondaryConstructor(val impl: KtSecondaryConstructor) : SecondaryConstructor, KotlinConstructor { override fun impl(): KtSecondaryConstructor = impl + override fun getDelegationCall(): ConstructorDelegationCall? = impl().getDelegationCallOrNull()?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSelfType.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSelfType.kt index 2678c1e8..856e3a0a 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSelfType.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSelfType.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtSelfType fun interface KotlinSelfType : SelfType, KotlinTypeElement { override fun impl(): KtSelfType + override val typeArgumentsAsTypes: List get() = impl().typeArgumentsAsTypes.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSimpleNameExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSimpleNameExpression.kt index 8cfe3ebb..8b295305 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSimpleNameExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSimpleNameExpression.kt @@ -6,6 +6,7 @@ import org.jetbrains.kotlin.psi.KtSimpleNameExpression fun interface KotlinSimpleNameExpression : SimpleNameExpression, KotlinReferenceExpression { override fun impl(): KtSimpleNameExpression + override fun getReferencedName(): String = impl().getReferencedName() override fun getReferencedNameAsName(): Name = Name(impl().getReferencedNameAsName().asString()) diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSuperExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSuperExpression.kt index b2beba2d..1e90bf5c 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSuperExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSuperExpression.kt @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.psi.KtSuperExpression class KotlinSuperExpression(val impl: KtSuperExpression) : SuperExpression, KotlinInstanceExpressionWithLabel { override fun impl(): KtSuperExpression = impl + override val superTypeQualifier: TypeReference? get() = impl.superTypeQualifier?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSuperTypeListEntry.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSuperTypeListEntry.kt index ce8d8440..e414eace 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSuperTypeListEntry.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinSuperTypeListEntry.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtSuperTypeListEntry fun interface KotlinSuperTypeListEntry : SuperTypeListEntry, KotlinElement { override fun impl(): KtSuperTypeListEntry + override val typeReference: TypeReference? get() = impl().typeReference?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinThrowExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinThrowExpression.kt index c605889b..8688154f 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinThrowExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinThrowExpression.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtThrowExpression class KotlinThrowExpression(val impl: KtThrowExpression) : ThrowExpression, KotlinExpression { override fun impl(): KtThrowExpression = impl + override val thrownExpression: Expression? get() = impl().thrownExpression?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTryExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTryExpression.kt index b8c4a74d..f96483d7 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTryExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTryExpression.kt @@ -9,10 +9,13 @@ import org.jetbrains.kotlin.psi.KtTryExpression class KotlinTryExpression(val impl: KtTryExpression) : TryExpression, KotlinExpression { override fun impl(): KtTryExpression = impl + override val tryBlock: BlockExpression get() = impl().tryBlock.model() + override val catchClauses: List get() = impl().catchClauses.map { it.model() } + override val finallyBlock: FinallySection? get() = impl().finallyBlock?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeAlias.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeAlias.kt index 50d9e602..3885af4c 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeAlias.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeAlias.kt @@ -7,6 +7,8 @@ import org.jetbrains.kotlin.psi.KtTypeAlias class KotlinTypeAlias(val impl: KtTypeAlias) : TypeAlias, KotlinNamedDeclaration { override fun impl(): KtTypeAlias = impl + override fun isTopLevel(): Boolean = impl.isTopLevel() + override fun getTypeReference(): TypeReference? = impl.getTypeReference()?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeArgumentList.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeArgumentList.kt index bdd62f5c..de4444d9 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeArgumentList.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeArgumentList.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtTypeArgumentList class KotlinTypeArgumentList(val impl: KtTypeArgumentList) : TypeArgumentList, KotlinElement { override fun impl(): KtTypeArgumentList = impl + override val arguments: List get() = impl().arguments.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeCastExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeCastExpression.kt index 182f3fec..df1ae733 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeCastExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeCastExpression.kt @@ -13,10 +13,13 @@ class KotlinTypeCastExpression(val impl: KtBinaryExpressionWithTypeRHS) : override val operationToken: String get() = this.operationReference.getReferencedName() + override val left: Expression get() = impl.left.model() + override val right: TypeReference? get() = impl.right?.model() + override val kind: TypeCastExpresionKind get() = when (operationToken) { diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeConstraint.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeConstraint.kt index e176adc6..bb89130a 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeConstraint.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeConstraint.kt @@ -8,8 +8,10 @@ import org.jetbrains.kotlin.psi.KtTypeConstraint class KotlinTypeConstraint(val impl: KtTypeConstraint) : TypeConstraint, KotlinElement { override fun impl(): KtTypeConstraint = impl + override val subjectTypeParameterName: SimpleNameExpression? get() = impl().subjectTypeParameterName?.model() + override val boundTypeReference: TypeReference? get() = impl().boundTypeReference?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeConstraintList.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeConstraintList.kt index 598f199b..7be079d5 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeConstraintList.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeConstraintList.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtTypeConstraintList class KotlinTypeConstraintList(val impl: KtTypeConstraintList) : TypeConstraintList, KotlinElement { override fun impl(): KtTypeConstraintList = impl + override val constraints: List get() = impl().constraints.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeElement.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeElement.kt index 08ba8f2b..0e3b9022 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeElement.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeElement.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtTypeElement fun interface KotlinTypeElement : TypeElement, KotlinElement { override fun impl(): KtTypeElement + override val typeArgumentsAsTypes: List get() = impl().typeArgumentsAsTypes.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameter.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameter.kt index fbef141a..3acf060e 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameter.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameter.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.types.Variance.OUT_VARIANCE class KotlinTypeParameter(val impl: KtTypeParameter) : TypeParameter, KotlinNamedDeclaration { override fun impl(): KtTypeParameter = impl + override val variance: Variance get() = when (impl().variance) { @@ -18,6 +19,7 @@ class KotlinTypeParameter(val impl: KtTypeParameter) : TypeParameter, KotlinName IN_VARIANCE -> Variance.In OUT_VARIANCE -> Variance.Out } + override val extendsBounds: List get() = listOfNotNull(impl().extendsBound?.model()) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameterList.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameterList.kt index 562f5033..ad36d6e5 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameterList.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameterList.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtTypeParameterList class KotlinTypeParameterList(val impl: KtTypeParameterList) : TypeParameterList, KotlinElement { override fun impl(): KtTypeParameterList = impl + override val parameters: List get() = impl().parameters.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameterListOwner.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameterListOwner.kt index 866b1025..adcfa569 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameterListOwner.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeParameterListOwner.kt @@ -10,12 +10,16 @@ import org.jetbrains.kotlin.psi.KtTypeParameterListOwner fun interface KotlinTypeParameterListOwner : TypeParameterListOwner, KotlinNamedDeclaration { override fun impl(): KtTypeParameterListOwner + override val typeParameterList: TypeParameterList? get() = impl().typeParameterList?.model() + override val typeConstraintList: TypeConstraintList? get() = impl().typeConstraintList?.model() + override val typeConstraints: List get() = impl().typeConstraints.map { it.model() } + override val typeParameters: List get() = impl().typeParameters.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeProjection.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeProjection.kt index 32f182f8..f6407275 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeProjection.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeProjection.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.psi.KtTypeProjection fun interface KotlinTypeProjection : TypeProjection { fun impl(): KtTypeProjection + override val projectionKind: ProjectionKind get() = when (impl().projectionKind) { @@ -17,6 +18,7 @@ fun interface KotlinTypeProjection : TypeProjection { KtProjectionKind.STAR -> ProjectionKind.STAR KtProjectionKind.NONE -> ProjectionKind.NONE } + override val typeReference: TypeReference? get() = impl().typeReference?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeReference.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeReference.kt index 436ba27d..eef2ff36 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeReference.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinTypeReference.kt @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.psi.KtTypeReference class KotlinTypeReference(val impl: KtTypeReference) : TypeReference, KotlinAnnotated, KotlinAnnotationsContainer { override fun impl(): KtTypeReference = impl + override val typeElement: TypeElement? get() = impl().typeElement?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinUnaryExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinUnaryExpression.kt index 99bb53ff..c3a6fc55 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinUnaryExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinUnaryExpression.kt @@ -9,8 +9,10 @@ import org.jetbrains.kotlin.psi.KtUnaryExpression class KotlinUnaryExpression(val impl: KtUnaryExpression) : UnaryExpression, KotlinExpression, KotlinOperationExpression { override fun impl(): KtUnaryExpression = impl + override val baseExpression: Expression? get() = impl().baseExpression?.model() + override val operationReference: SimpleNameExpression get() = impl().operationReference.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinValueArgumentList.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinValueArgumentList.kt index 1b530c66..f8d80b6e 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinValueArgumentList.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinValueArgumentList.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtValueArgumentList class KotlinValueArgumentList(val impl: KtValueArgumentList) : ValueArgumentList, KotlinElement { override fun impl(): KtValueArgumentList = impl + override val arguments: List get() = impl().arguments.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinValueArgumentName.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinValueArgumentName.kt index d7c54a8e..35daddd8 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinValueArgumentName.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinValueArgumentName.kt @@ -8,8 +8,10 @@ import arrow.meta.plugins.analysis.phases.analysis.solver.ast.kotlin.ast.model class KotlinValueArgumentName(val impl: org.jetbrains.kotlin.psi.ValueArgumentName) : ValueArgumentName { fun impl(): org.jetbrains.kotlin.psi.ValueArgumentName = impl + override val asName: Name get() = Name(impl().asName.asString()) + override val referenceExpression: SimpleNameExpression? get() = impl().referenceExpression?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionInRange.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionInRange.kt index d429b273..8a14e125 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionInRange.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionInRange.kt @@ -9,10 +9,13 @@ import org.jetbrains.kotlin.psi.KtWhenConditionInRange class KotlinWhenConditionInRange(val impl: KtWhenConditionInRange) : WhenConditionInRange, KotlinWhenCondition { override fun impl(): KtWhenConditionInRange = impl + override val isNegated: Boolean get() = impl().isNegated + override val rangeExpression: Expression? get() = impl().rangeExpression?.model() + override val operationReference: OperationReferenceExpression get() = impl().operationReference.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionIsPattern.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionIsPattern.kt index 3552ee69..2891a4d6 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionIsPattern.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionIsPattern.kt @@ -8,8 +8,10 @@ import org.jetbrains.kotlin.psi.KtWhenConditionIsPattern class KotlinWhenConditionIsPattern(val impl: KtWhenConditionIsPattern) : WhenConditionIsPattern, KotlinWhenCondition { override fun impl(): KtWhenConditionIsPattern = impl + override val isNegated: Boolean get() = impl().isNegated + override val typeReference: TypeReference? get() = impl().typeReference?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionWithExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionWithExpression.kt index 17167533..76743244 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionWithExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenConditionWithExpression.kt @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.psi.KtWhenConditionWithExpression class KotlinWhenConditionWithExpression(val impl: KtWhenConditionWithExpression) : WhenConditionWithExpression, KotlinWhenCondition { override fun impl(): KtWhenConditionWithExpression = impl + override val expression: Expression? get() = impl().expression?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenEntry.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenEntry.kt index b598e293..333c0a86 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenEntry.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenEntry.kt @@ -8,10 +8,13 @@ import org.jetbrains.kotlin.psi.KtWhenEntry class KotlinWhenEntry(val impl: KtWhenEntry) : WhenEntry, KotlinElement { override fun impl(): KtWhenEntry = impl + override val isElse: Boolean get() = impl().isElse + override val expression: Expression? get() = impl().expression?.model() + override val conditions: List get() = impl().conditions.map { it.model() } } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenExpression.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenExpression.kt index d8085a0a..52c3b2c2 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenExpression.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhenExpression.kt @@ -13,10 +13,13 @@ class KotlinWhenExpression(val impl: KtWhenExpression) : WhenExpression, KotlinE override val entries: List get() = impl().entries.map { it.model() } + override val subjectVariable: Property? get() = impl().subjectVariable?.model() + override val subjectExpression: Expression? get() = impl().subjectExpression?.model() + override val elseExpression: Expression? get() = impl().subjectExpression?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhileExpressionBase.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhileExpressionBase.kt index 0b9a1806..feb29bc4 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhileExpressionBase.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/elements/KotlinWhileExpressionBase.kt @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.KtWhileExpressionBase fun interface KotlinWhileExpressionBase : WhileExpressionBase, KotlinLoopExpression { override fun impl(): KtWhileExpressionBase + override val condition: Expression? get() = impl().condition?.model() } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/types/KotlinType.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/types/KotlinType.kt index 9c35ea65..4b6df18b 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/types/KotlinType.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/types/KotlinType.kt @@ -25,10 +25,13 @@ import org.jetbrains.kotlin.types.typeUtil.isUnsignedNumberType internal class KotlinType(val impl: org.jetbrains.kotlin.types.KotlinType) : Type { override val descriptor: ClassDescriptor? get() = TypeUtils.getClassDescriptor(impl)?.model() + override val unwrappedNotNullableType: Type get() = KotlinType(impl.unwrappedNotNullableType) + override val isMarkedNullable: Boolean get() = impl.isMarkedNullable + override val arguments: List get() = impl.arguments.map { KotlinTypeProjection(it) } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/types/KotlinTypeProjection.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/types/KotlinTypeProjection.kt index 94d1e86c..813b7a38 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/types/KotlinTypeProjection.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/analysis/solver/ast/kotlin/types/KotlinTypeProjection.kt @@ -12,8 +12,10 @@ class KotlinTypeProjection(val impl: org.jetbrains.kotlin.types.TypeProjection) org.jetbrains.kotlin.types.Variance.OUT_VARIANCE -> Variance.Out org.jetbrains.kotlin.types.Variance.INVARIANT -> Variance.Invariant } + override val type: Type get() = KotlinType(impl.type) + override val isStarProjection: Boolean get() = impl.isStarProjection } diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/ConstraintsAnnotations.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/ConstraintsAnnotations.kt index 982c7c2c..f83ca24c 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/ConstraintsAnnotations.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/ConstraintsAnnotations.kt @@ -48,7 +48,7 @@ internal fun IrUtils.annotateWithConstraints(solverState: SolverState, fn: IrFun } notLookAnnotation( declarationConstraints.doNotLookAtArgumentsWhen, - solverState.solver.formulaManager + solverState.solver.formulaManager, ) ?.let { fn.addAnnotation(it) } if (model.isALaw()) { @@ -80,8 +80,7 @@ private fun getIrReturnedExpressionWithoutPostcondition(function: IrFunction): F else -> null } else -> null - } - ?: lastElementWithoutReturn + } ?: lastElementWithoutReturn // and finally obtain the model return when (veryLast) { is IrMemberAccessExpression<*> -> @@ -102,35 +101,35 @@ private fun IrMutableAnnotationContainer.addAnnotation(annotation: IrConstructor private fun IrUtils.preAnnotation( formulae: List, - manager: FormulaManager + manager: FormulaManager, ): IrConstructorCall? = annotationFromClassId( ClassId.fromString("arrow/analysis/Pre"), formulae.map { it.msg }, formulae.map { it.formula.toString() }, - formulae.flatMap { manager.fieldNames(it.formula).map { fld -> fld.first }.toSet() } + formulae.flatMap { manager.fieldNames(it.formula).map { fld -> fld.first }.toSet() }, ) private fun IrUtils.postAnnotation( formulae: List, - manager: FormulaManager + manager: FormulaManager, ): IrConstructorCall? = annotationFromClassId( ClassId.fromString("arrow/analysis/Post"), formulae.map { it.msg }, formulae.map { it.formula.toString() }, - formulae.flatMap { manager.fieldNames(it.formula).map { fld -> fld.first }.toSet() } + formulae.flatMap { manager.fieldNames(it.formula).map { fld -> fld.first }.toSet() }, ) private fun IrUtils.notLookAnnotation( formulae: List, - manager: FormulaManager + manager: FormulaManager, ): IrConstructorCall? = annotationFromClassId( ClassId.fromString("arrow/analysis/DoNotLookAtArguments"), formulae.map { it.msg }, formulae.map { it.formula.toString() }, - formulae.flatMap { manager.fieldNames(it.formula).map { fld -> fld.first }.toSet() } + formulae.flatMap { manager.fieldNames(it.formula).map { fld -> fld.first }.toSet() }, ) private fun IrUtils.lawSubjectAnnotation(descriptor: FunctionDescriptor): IrConstructorCall? = @@ -140,7 +139,7 @@ private fun IrUtils.annotationFromClassId( classId: ClassId, messages: List, formulae: List, - dependencies: List + dependencies: List, ): IrConstructorCall? = when { formulae.isEmpty() -> null @@ -152,7 +151,7 @@ private fun IrUtils.annotationFromClassId( private fun IrUtils.lawSubjectAnnotationFromClassId( classId: ClassId, - descriptor: FunctionDescriptor + descriptor: FunctionDescriptor, ): IrConstructorCall? = moduleFragment.descriptor.findClassAcrossModuleDependencies(classId)?.let { lawSubjectAnnotation(descriptor, it) @@ -160,7 +159,7 @@ private fun IrUtils.lawSubjectAnnotationFromClassId( private fun IrUtils.lawSubjectAnnotation( fnDescriptor: FunctionDescriptor, - descriptor: ClassDescriptor + descriptor: ClassDescriptor, ): IrConstructorCall? = descriptor.irConstructorCall()?.also { it.putValueArgument(0, constantValue(fnDescriptor.fqNameSafe.name)) @@ -170,7 +169,7 @@ private fun IrUtils.annotation( messages: List, formulae: List, dependencies: List, - descriptor: ClassDescriptor + descriptor: ClassDescriptor, ): IrConstructorCall? = descriptor.irConstructorCall()?.also { it.putValueArgument(0, arrayOfStrings(messages)) @@ -191,15 +190,15 @@ private fun IrUtils.arrayOfStrings(values: List): IrVarargImpl? = endOffset = UNDEFINED_OFFSET, type = it.returnType?.toIrType()!!, varargElementType = moduleFragment.irBuiltins.stringType, - elements = values.map(this::constantValue) + elements = values.map(this::constantValue), ) } -private fun IrUtils.constantValue(value: String): IrConst = +private fun IrUtils.constantValue(value: String): IrConst = IrConstImpl( startOffset = UNDEFINED_OFFSET, endOffset = UNDEFINED_OFFSET, type = moduleFragment.irBuiltins.stringType, kind = IrConstKind.String, - value = value + value = value, ) diff --git a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/Hints.kt b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/Hints.kt index 0c2e0e51..8cbe2831 100644 --- a/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/Hints.kt +++ b/analysis/kotlin-plugin/src/main/kotlin/arrow/meta/plugins/analysis/phases/ir/Hints.kt @@ -9,16 +9,12 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor fun CompilerContext.hintsFile( parentPath: String, descriptor: ModuleDescriptor, - packages: Set + packages: Set, ): File = - File( - parentPath, - "/AnalysisHints.kt", - ) - .also { - it.createNewFile() - it.writeText(hints(descriptor, packages)) - } + File(parentPath, "/AnalysisHints.kt").also { + it.createNewFile() + it.writeText(hints(descriptor, packages)) + } fun hints(descriptor: ModuleDescriptor, packages: Set): String { val hintPackageName = @@ -38,5 +34,5 @@ fun hints(descriptor: ModuleDescriptor, packages: Set): String { enum class HintState { NeedsProcessing, - Processed + Processed, } diff --git a/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/Utils.kt b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/Utils.kt index bea0fd12..83427d9f 100644 --- a/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/Utils.kt +++ b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/Utils.kt @@ -10,7 +10,7 @@ fun ConfigSyntax.newMetaDependencies(): List { val analysisPlugin = CompilerPlugin( "AnalysisPlugin", - listOf(Dependency("arrow-analysis-kotlin-plugin:$currentVersion")) + listOf(Dependency("arrow-analysis-kotlin-plugin:$currentVersion")), ) return metaDependencies + addCompilerPlugins(analysisPlugin) + diff --git a/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/AnalysisTests.kt b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/AnalysisTests.kt index d61e3007..792cecaa 100644 --- a/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/AnalysisTests.kt +++ b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/AnalysisTests.kt @@ -19,7 +19,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("not parse predicate") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -34,7 +34,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("unexpected reference") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -48,7 +48,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -62,7 +62,7 @@ class AnalysisTests { } """( withPlugin = { compilesWith { it.contains("not parse predicate") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -79,7 +79,7 @@ class AnalysisTests { val result = bar(1) """( withPlugin = { failsWith { it.contains("inconsistent pre-conditions") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -91,7 +91,7 @@ class AnalysisTests { 3.post({ it > 0 }) { "greater than 0" } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -107,7 +107,7 @@ class AnalysisTests { it.contains("declaration `bar` fails to satisfy the post-condition: ${'$'}result < 0") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -124,7 +124,7 @@ class AnalysisTests { it.contains("in branch: !(x > 0)") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -136,7 +136,7 @@ class AnalysisTests { 0.let { it + 1 }.post({ it > 0 }) { "greater than 0" } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -148,7 +148,7 @@ class AnalysisTests { 1.run { this - 1 }.post({ it > 0 }) { "greater than 0" } """( withPlugin = { failsWith { it.contains("fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -167,7 +167,7 @@ class AnalysisTests { it.contains("declaration `bar` fails to satisfy the post-condition: ${'$'}result > 0") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -182,7 +182,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("invariants are not satisfied in `z = 0`") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -201,7 +201,7 @@ class AnalysisTests { it.contains("declaration `bar` fails to satisfy the post-condition: ${'$'}result > 0") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -216,7 +216,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -232,7 +232,7 @@ class AnalysisTests { withPlugin = { compilesWith { it.contains("unreachable code due to conflicting conditions") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -249,7 +249,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -265,7 +265,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -279,7 +279,7 @@ class AnalysisTests { }.post({ it >= 0 }) { "result >= 0" } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -297,7 +297,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `x is 42` is not satisfied in `bar(1)`") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -313,7 +313,7 @@ class AnalysisTests { val result = unsafeCall(bar(1)) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -329,7 +329,7 @@ class AnalysisTests { val result = unsafeBlock { bar(1) } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -345,7 +345,7 @@ class AnalysisTests { val result = unsafeBlock { bar(1) + 1 } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -362,7 +362,7 @@ class AnalysisTests { val result = bar(1) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -384,7 +384,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `(< (int x) 0)` is not satisfied in `bar(1)") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -406,7 +406,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `(< (int x) 0)` is not satisfied in `bar(1)`") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -422,7 +422,7 @@ class AnalysisTests { val result = bar(1) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -440,7 +440,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `x less than 10` is not satisfied in `bar(30)`") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -457,7 +457,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `not zero divisor` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -474,7 +474,7 @@ class AnalysisTests { val x: Result = success(3) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -487,7 +487,7 @@ class AnalysisTests { fun Collection.minusLaw(element: E) = minus(element) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -500,7 +500,7 @@ class AnalysisTests { fun List.firstLaw(predicate: (x: E) -> Boolean) = first(predicate) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -520,7 +520,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `other is not zero` is not satisfied in `1 / 0`") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -541,7 +541,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -564,7 +564,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `other is not zero` is not satisfied in `1 / 0`") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -585,7 +585,7 @@ class AnalysisTests { val result = 1 / 2 """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -605,7 +605,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `other is not zero` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -625,7 +625,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `other is not zero` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -642,7 +642,7 @@ class AnalysisTests { it.contains("pre-condition `initial capacity should be non-negative` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -655,7 +655,7 @@ class AnalysisTests { val result = ArrayList(1) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -680,7 +680,7 @@ class AnalysisTests { it.contains("pre-condition `initial capacity should be non-negative` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -696,7 +696,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("must use the arguments in order") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -723,7 +723,7 @@ class AnalysisTests { it.contains("pre-condition `index smaller than size` is not satisfied in `get(0)`") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -752,7 +752,7 @@ class AnalysisTests { ) } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -778,7 +778,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -805,7 +805,7 @@ class AnalysisTests { else entries.all { entry -> entry.id == entries[0].id } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -822,7 +822,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -838,8 +838,12 @@ class AnalysisTests { }) { "smaller than 0" } } """( - withPlugin = { failsWith { it.contains("`nully1b` fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withPlugin = { + failsWith { + it.contains("`nully1b` fails to satisfy the post-condition") + } + }, + withoutPlugin = { compiles }, ) } @@ -858,7 +862,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("`nully1b` fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -873,7 +877,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -887,7 +891,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -901,7 +905,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("`nully3` fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -915,7 +919,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -929,7 +933,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -943,7 +947,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("`try2` fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -960,7 +964,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("`f` fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -981,7 +985,7 @@ class AnalysisTests { it.contains("post-condition `greater than 0` from overridden member is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1006,7 +1010,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1029,7 +1033,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("declaration `f` fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1052,7 +1056,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `n must be positive` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1073,7 +1077,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("declaration `A` fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1093,7 +1097,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `n must be positive` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1113,7 +1117,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1133,7 +1137,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1152,7 +1156,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `n must be positive` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1172,7 +1176,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `n must be positive` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1192,7 +1196,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("declaration `A` fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1214,7 +1218,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `ensure positive answer` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1235,7 +1239,7 @@ class AnalysisTests { val result: Int = Color.RED.rgb.post({ it != 0 }) { "check this" } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1254,7 +1258,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("pre-condition `positive` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1274,7 +1278,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `greater than ten` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1292,7 +1296,7 @@ class AnalysisTests { val result = f(emptyList()) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1306,7 +1310,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("has inconsistent default values") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1323,7 +1327,7 @@ class AnalysisTests { val result2 = f(3) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1337,7 +1341,7 @@ class AnalysisTests { } """( withPlugin = { failsWith { it.contains("fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1358,7 +1362,7 @@ class AnalysisTests { failure(e).post({ it.isFailure == true }) { "create a failure" } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1372,7 +1376,7 @@ class AnalysisTests { lazyOf(value).post({ it.value == value }) { "lazy value is argument" } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1385,7 +1389,7 @@ class AnalysisTests { val problem = emptyList().map { it + 1 }.first() """( withPlugin = { failsWith { it.contains("pre-condition `not empty` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1398,7 +1402,7 @@ class AnalysisTests { val oki = emptyList().map { it + 1 } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1412,7 +1416,7 @@ class AnalysisTests { val problem = emptyList().map(::addOne).first() """( withPlugin = { failsWith { it.contains("pre-condition `not empty` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1437,7 +1441,7 @@ class AnalysisTests { val oki = emptyList().first() """( withPlugin = { failsWith { it.contains("pre-condition `not empty` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1455,7 +1459,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `not empty name` is not satisfied in `bar(\"\")`") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1471,7 +1475,7 @@ class AnalysisTests { val result = bar("alex") """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1488,7 +1492,7 @@ class AnalysisTests { val result = bar("${'$'}{1 + 2}") """( withPlugin = { failsWith { it.contains("pre-condition `not empty name` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1514,7 +1518,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1533,7 +1537,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1553,7 +1557,7 @@ class AnalysisTests { val example = A() """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1575,7 +1579,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("declaration `A` fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1597,7 +1601,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("declaration `A` fails to satisfy the post-condition") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1611,7 +1615,7 @@ class AnalysisTests { this.all { n -> n == first() } """( withPlugin = { failsWith { it.contains("pre-condition `not empty` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1631,7 +1635,7 @@ class AnalysisTests { this.all { n -> n == first() } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1649,7 +1653,7 @@ class AnalysisTests { val l = listOf().x() """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1667,7 +1671,7 @@ class AnalysisTests { val l = mapOf().x() """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1684,7 +1688,7 @@ class AnalysisTests { Example { content -> content.length } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1702,7 +1706,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1714,7 +1718,7 @@ class AnalysisTests { fun f(div: Int, floor: Int): Int = div / floor """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1733,7 +1737,7 @@ class AnalysisTests { val other = g(String::capitalize) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1748,7 +1752,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1761,7 +1765,7 @@ class AnalysisTests { fun g(x: Any): Int? = (x as? Int)?.let { it + 1 } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1777,7 +1781,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1795,7 +1799,7 @@ class AnalysisTests { withPlugin = { failsWith { it.contains("pre-condition `n must be positive` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1807,7 +1811,7 @@ class AnalysisTests { val p by lazy { object : Any() {} } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1820,7 +1824,7 @@ class AnalysisTests { val p: Int by lazy { emptyList().first() } """( withPlugin = { failsWith { it.contains("pre-condition `not empty` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1835,7 +1839,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1854,7 +1858,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1867,7 +1871,7 @@ class AnalysisTests { val ok = listOf(1).first() """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1880,7 +1884,7 @@ class AnalysisTests { val ok = listOf(1, 2).first() """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1893,7 +1897,7 @@ class AnalysisTests { val ok = listOf().first() """( withPlugin = { failsWith { it.contains("pre-condition `not empty` is not satisfied") } }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1906,7 +1910,7 @@ class AnalysisTests { val ok = listOf(-1).map { it + 1 }.first() """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1924,7 +1928,7 @@ class AnalysisTests { """( withPlugin = { failsWith { it.contains("pre-condition `not empty` is not satisfied") } }, withoutPlugin = { compiles }, - isMultiplatform = true + isMultiplatform = true, ) } @@ -1939,7 +1943,7 @@ class AnalysisTests { Field(tag, field) """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1969,7 +1973,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } @@ -1997,7 +2001,7 @@ class AnalysisTests { } """( withPlugin = { compilesNoUnreachable }, - withoutPlugin = { compiles } + withoutPlugin = { compiles }, ) } } @@ -2105,7 +2109,7 @@ fun CharSequence.isNotEmptyLaw(): Boolean = private operator fun String.invoke( withPlugin: AssertSyntax.() -> Assert, withoutPlugin: AssertSyntax.() -> Assert, - isMultiplatform: Boolean = false + isMultiplatform: Boolean = false, ) { assertThis( CompilerTest( @@ -2115,7 +2119,10 @@ private operator fun String.invoke( // "value")) }, code = { this@invoke.source }, - assert = { withPlugin() } + assert = { + val result = withPlugin() + result + }, ) ) assertThis( @@ -2125,7 +2132,10 @@ private operator fun String.invoke( listOf(addArguments("-Xmulti-platform")).filter { isMultiplatform } }, code = { this@invoke.source }, - assert = { withoutPlugin() } + assert = { + val result = withoutPlugin() + result + }, ) ) } diff --git a/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/GenerateTests.kt b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/GenerateTests.kt new file mode 100644 index 00000000..96817eae --- /dev/null +++ b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/GenerateTests.kt @@ -0,0 +1,19 @@ +package arrow.meta.plugins.analysis + +import org.jetbrains.kotlin.generators.generateTestGroupSuiteWithJUnit5 +import arrow.meta.plugins.analysis.runners.AbstractBoxTest +import arrow.meta.plugins.analysis.runners.AbstractDiagnosticTest + +fun main() { + generateTestGroupSuiteWithJUnit5 { + testGroup(testDataRoot = "src/testData", testsRoot = "src/test-gen") { + testClass { + model("diagnostics") + } + + testClass { + model("box") + } + } + } +} diff --git a/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/runners/AbstractBoxTest.kt b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/runners/AbstractBoxTest.kt new file mode 100644 index 00000000..59b6f40c --- /dev/null +++ b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/runners/AbstractBoxTest.kt @@ -0,0 +1,61 @@ +package arrow.meta.plugins.analysis.runners + +import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.test.FirParser +import org.jetbrains.kotlin.test.TargetBackend +import org.jetbrains.kotlin.test.backend.BlackBoxCodegenSuppressor +import org.jetbrains.kotlin.test.backend.handlers.IrTextDumpHandler +import org.jetbrains.kotlin.test.backend.handlers.IrTreeVerifierHandler +import org.jetbrains.kotlin.test.backend.handlers.JvmBoxRunner +import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade +import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.fir2IrStep +import org.jetbrains.kotlin.test.builders.irHandlersStep +import org.jetbrains.kotlin.test.builders.jvmArtifactsHandlersStep +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_IR +import org.jetbrains.kotlin.test.directives.configureFirParser +import org.jetbrains.kotlin.test.model.DependencyKind +import org.jetbrains.kotlin.test.runners.RunnerWithTargetBackendForTestGeneratorMarker + +/* + * Containers of different directives, which can be used in tests: + * - ModuleStructureDirectives + * - LanguageSettingsDirectives + * - DiagnosticsDirectives + * - CodegenTestDirectives + * + * All of them are located in `org.jetbrains.kotlin.test.directives` package + */ +open class AbstractBoxTest : BaseTestRunner(), RunnerWithTargetBackendForTestGeneratorMarker { + override val targetBackend: TargetBackend + get() = TargetBackend.JVM_IR + + override fun TestConfigurationBuilder.configuration() { + globalDefaults { + targetBackend = TargetBackend.JVM_IR + targetPlatform = JvmPlatforms.defaultJvmPlatform + dependencyKind = DependencyKind.Binary + } + + configureFirParser(FirParser.Psi) + + defaultDirectives { + +DUMP_IR + } + + commonFirWithPluginFrontendConfiguration() + fir2IrStep() + irHandlersStep { + useHandlers( + ::IrTextDumpHandler, + ::IrTreeVerifierHandler, + ) + } + facadeStep(::JvmIrBackendFacade) + jvmArtifactsHandlersStep { + useHandlers(::JvmBoxRunner) + } + + useAfterAnalysisCheckers(::BlackBoxCodegenSuppressor) + } +} diff --git a/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/runners/AbstractDiagnosticTest.kt b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/runners/AbstractDiagnosticTest.kt new file mode 100644 index 00000000..4eecb3fe --- /dev/null +++ b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/runners/AbstractDiagnosticTest.kt @@ -0,0 +1,18 @@ +package arrow.meta.plugins.analysis.runners + +import org.jetbrains.kotlin.test.FirParser +import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.directives.configureFirParser +import org.jetbrains.kotlin.test.services.EnvironmentBasedStandardLibrariesPathProvider +import org.jetbrains.kotlin.test.services.KotlinStandardLibrariesPathProvider + +abstract class AbstractDiagnosticTest : BaseTestRunner() { + override fun TestConfigurationBuilder.configuration() { + commonFirWithPluginFrontendConfiguration() + configureFirParser(FirParser.Psi) + } + + override fun createKotlinStandardLibrariesPathProvider(): KotlinStandardLibrariesPathProvider { + return EnvironmentBasedStandardLibrariesPathProvider + } +} diff --git a/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/runners/BaseTestRunner.kt b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/runners/BaseTestRunner.kt new file mode 100644 index 00000000..7f25f7e2 --- /dev/null +++ b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/runners/BaseTestRunner.kt @@ -0,0 +1,42 @@ +package arrow.meta.plugins.analysis.runners + +import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives +import org.jetbrains.kotlin.test.initIdeaConfiguration +import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerTest +import org.jetbrains.kotlin.test.runners.baseFirDiagnosticTestConfiguration +import org.jetbrains.kotlin.test.services.EnvironmentBasedStandardLibrariesPathProvider +import org.jetbrains.kotlin.test.services.KotlinStandardLibrariesPathProvider +import org.junit.jupiter.api.BeforeAll +import arrow.meta.plugins.analysis.services.ExtensionRegistrarConfigurator +import arrow.meta.plugins.analysis.services.PluginAnnotationsProvider +import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives + +abstract class BaseTestRunner : AbstractKotlinCompilerTest() { + companion object { + @BeforeAll + @JvmStatic + fun setUp() { + initIdeaConfiguration() + } + } + + override fun createKotlinStandardLibrariesPathProvider(): KotlinStandardLibrariesPathProvider { + return EnvironmentBasedStandardLibrariesPathProvider + } +} + +fun TestConfigurationBuilder.commonFirWithPluginFrontendConfiguration() { + baseFirDiagnosticTestConfiguration() + + defaultDirectives { + +FirDiagnosticsDirectives.ENABLE_PLUGIN_PHASES + +FirDiagnosticsDirectives.FIR_DUMP + +JvmEnvironmentConfigurationDirectives.FULL_JDK + } + + useConfigurators( + ::PluginAnnotationsProvider, + ::ExtensionRegistrarConfigurator + ) +} diff --git a/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/services/ExtensionRegistrarConfigurator.kt b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/services/ExtensionRegistrarConfigurator.kt new file mode 100644 index 00000000..6688fb25 --- /dev/null +++ b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/services/ExtensionRegistrarConfigurator.kt @@ -0,0 +1,19 @@ +package arrow.meta.plugins.analysis.services + +import arrow.meta.FirAnalysisPluginRegistrar +import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar +import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.EnvironmentConfigurator +import org.jetbrains.kotlin.test.services.TestServices + +class ExtensionRegistrarConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) { + override fun CompilerPluginRegistrar.ExtensionStorage.registerCompilerExtensions( + module: TestModule, + configuration: CompilerConfiguration + ) { + FirExtensionRegistrarAdapter.registerExtension(FirAnalysisPluginRegistrar()) + //IrGenerationExtension.registerExtension(SimpleIrGenerationExtension()) + } +} diff --git a/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/services/PluginAnnotationsProvider.kt b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/services/PluginAnnotationsProvider.kt new file mode 100644 index 00000000..9a9ff202 --- /dev/null +++ b/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/services/PluginAnnotationsProvider.kt @@ -0,0 +1,26 @@ +package arrow.meta.plugins.analysis.services + +import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot +import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.EnvironmentConfigurator +import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.assertions +import java.io.File +import java.io.FilenameFilter + +class PluginAnnotationsProvider(testServices: TestServices) : EnvironmentConfigurator(testServices) { + companion object { + private const val ANNOTATIONS_JAR_DIR = "../laws/build/libs/" + private val ANNOTATIONS_JAR_FILTER = FilenameFilter { _, name -> name.startsWith("arrow-analysis-laws") && name.endsWith(".jar") } + } + + override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) { + val libDir = File(ANNOTATIONS_JAR_DIR) + testServices.assertions.assertTrue(libDir.exists() && libDir.isDirectory, failMessage) + val jar = libDir.listFiles(ANNOTATIONS_JAR_FILTER)?.firstOrNull() ?: testServices.assertions.fail(failMessage) + configuration.addJvmClasspathRoot(jar) + } + + private val failMessage = { "Jar with annotations does not exist. Please run :arrow-analysis-laws:jvmJar" } +} diff --git a/analysis/kotlin-plugin/src/testData/box/anotherBoxTest.kt b/analysis/kotlin-plugin/src/testData/box/anotherBoxTest.kt new file mode 100644 index 00000000..bc21aa34 --- /dev/null +++ b/analysis/kotlin-plugin/src/testData/box/anotherBoxTest.kt @@ -0,0 +1,7 @@ +// WITH_STDLIB + +fun box(): String { + val list = listOf("aaa", "bb", "c") + val result = list.map { it.length }.sum() + return if (result == 6) "OK" else "Fail: $result" +} diff --git a/analysis/kotlin-plugin/src/testData/box/simple.kt b/analysis/kotlin-plugin/src/testData/box/simple.kt new file mode 100644 index 00000000..77683064 --- /dev/null +++ b/analysis/kotlin-plugin/src/testData/box/simple.kt @@ -0,0 +1,6 @@ +package foo.bar + +fun box(): String { + val result = MyClass().foo() + return if (result == "Hello world") { "OK" } else { "Fail: $result" } +} diff --git a/analysis/kotlin-plugin/src/testData/diagnostics/anotherDiagnosticTest.fir.txt b/analysis/kotlin-plugin/src/testData/diagnostics/anotherDiagnosticTest.fir.txt new file mode 100644 index 00000000..d54a1aa2 --- /dev/null +++ b/analysis/kotlin-plugin/src/testData/diagnostics/anotherDiagnosticTest.fir.txt @@ -0,0 +1,35 @@ +Module: lib +FILE: foo.kt + package foo + + public final fun takeInt(x: R|kotlin/Int|): R|kotlin/Unit| { + } + public final fun test(): R|kotlin/Unit| { + R|foo/takeInt|(Int(10)) + R|foo/takeInt#|(String(Hello)) + } +FILE: __GENERATED DECLARATIONS__.kt + package foo.bar + + public final class MyClass : R|kotlin/Any| { + public final fun foo(): R|kotlin/String| + + public constructor(): R|foo/bar/MyClass| + + } +Module: main +FILE: bar.kt + package bar + + public final fun test(): R|kotlin/Unit| { + R|foo/takeInt|(Int(10)) + } +FILE: __GENERATED DECLARATIONS__.kt + package foo.bar + + public final class MyClass : R|kotlin/Any| { + public final fun foo(): R|kotlin/String| + + public constructor(): R|foo/bar/MyClass| + + } diff --git a/analysis/kotlin-plugin/src/testData/diagnostics/anotherDiagnosticTest.kt b/analysis/kotlin-plugin/src/testData/diagnostics/anotherDiagnosticTest.kt new file mode 100644 index 00000000..e60a3729 --- /dev/null +++ b/analysis/kotlin-plugin/src/testData/diagnostics/anotherDiagnosticTest.kt @@ -0,0 +1,20 @@ +// MODULE: lib +// FILE: foo.kt +package foo + +fun takeInt(x: Int) {} + +fun test() { + takeInt(10) + takeInt("Hello") +} + +// MODULE: main(lib) +// FILE: bar.kt +package bar + +import foo.takeInt + +fun test() { + takeInt(10) +} diff --git a/analysis/kotlin-plugin/src/testData/diagnostics/simple.fir.txt b/analysis/kotlin-plugin/src/testData/diagnostics/simple.fir.txt new file mode 100644 index 00000000..63132c66 --- /dev/null +++ b/analysis/kotlin-plugin/src/testData/diagnostics/simple.fir.txt @@ -0,0 +1,16 @@ +FILE: simple.kt + package foo.bar + + @R|org/itmo/my/pretty/plugin/SomeAnnotation|() public final fun test(): R|kotlin/Unit| { + lval s: R|kotlin/String| = R|foo/bar/MyClass|().R|foo/bar/MyClass.foo|() + R|/s|.#() + } +FILE: __GENERATED DECLARATIONS__.kt + package foo.bar + + public final class MyClass : R|kotlin/Any| { + public final fun foo(): R|kotlin/String| + + public constructor(): R|foo/bar/MyClass| + + } diff --git a/analysis/kotlin-plugin/src/testData/diagnostics/simple.kt b/analysis/kotlin-plugin/src/testData/diagnostics/simple.kt new file mode 100644 index 00000000..7c96b2f0 --- /dev/null +++ b/analysis/kotlin-plugin/src/testData/diagnostics/simple.kt @@ -0,0 +1,9 @@ +package foo.bar + +import org.itmo.my.pretty.plugin.SomeAnnotation + +@SomeAnnotation +fun test() { + val s = MyClass().foo() + s.inc() // should be an error +} diff --git a/analysis/laws/build.gradle.kts b/analysis/laws/build.gradle.kts index 8c1875ee..77c104eb 100644 --- a/analysis/laws/build.gradle.kts +++ b/analysis/laws/build.gradle.kts @@ -20,36 +20,39 @@ kotlin { commonMain { dependencies { implementation(libs.kotlin.stdlibCommon) + implementation(kotlin("stdlib-common")) api(projects.arrowAnalysisTypes) } } - named("jvmMain") { + jvmMain { dependencies { implementation(libs.kotlin.stdlibJDK8) + implementation(kotlin("stdlib-jdk8")) } } - named("jsMain") { + jsMain { dependencies { implementation(libs.kotlin.stdlibJS) + implementation(kotlin("stdlib-js")) } } } } dependencies { - kotlinCompilerClasspath(projects.arrowAnalysisKotlinPlugin) + kotlinCompilerPluginClasspath(projects.arrowAnalysisKotlinPlugin) } tasks.compileKotlinJvm { - kotlinOptions { + compilerOptions { dependsOn(":arrow-analysis-kotlin-plugin:jar") - freeCompilerArgs = listOf( + freeCompilerArgs.set(listOf( "-Xplugin=$rootDir/analysis/kotlin-plugin/build/libs/arrow-analysis-kotlin-plugin-$version.jar", "-P", "plugin:arrow.meta.plugin.compiler.analysis:generatedSrcOutputDir=$buildDir/generated/meta", "-P", "plugin:arrow.meta.plugin.compiler.analysis:baseDir=${project.rootProject.rootDir.path}" - ) + )) } } diff --git a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Array.kt b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Array.kt index 28b1ebf6..f0fbb9f2 100644 --- a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Array.kt +++ b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Array.kt @@ -14,16 +14,20 @@ object ArrayLaws { inline fun constructorLaw(size: Int, noinline init: (Int) -> E): Array { return Array(size, init).post({ it.size == size }) { "size is the given one" } } + @Law inline fun emptyArrayLaw(): Array = emptyArray().post({ it.size == 0 }) { "empty array" } @Law inline fun Array.sizeLaw(): Int = size.post({ it >= 0 }) { "size is non-negative" } + @Law inline fun Array.countLaw(): Int = count().post({ it == this.size }) { "count is size" } + @Law inline fun Array.countLaw(predicate: (E) -> Boolean): Int = count(predicate).post({ it <= this.size }) { "count bounded by size" } + @Law inline fun Array.lastIndexLaw(): Int = lastIndex.post({ it == size - 1 }) { "last index is size - 1" } @@ -31,12 +35,15 @@ object ArrayLaws { @Law inline fun Array.isEmptyLaw(): Boolean = isEmpty().post({ it == (size <= 0) }) { "empty when size is 0" } + @Law inline fun Array.noneLaw(): Boolean = none().post({ it == (size <= 0) }) { "none when size is 0" } + @Law inline fun Array.isNotEmptyLaw(): Boolean = isNotEmpty().post({ it == (size > 0) }) { "not empty when size is > 0" } + @Law inline fun Array?.isNullOrEmptyLaw(): Boolean = isNullOrEmpty().post({ it == ((this == null) || (this.size <= 0)) }) { @@ -48,6 +55,7 @@ object ArrayLaws { pre(index >= 0 && index < size) { "index within bounds" } return get(index) } + @Law inline fun Array.setLaw(index: Int, value: E) { pre(index >= 0 && index < size) { "index within bounds" } @@ -59,34 +67,41 @@ object ArrayLaws { pre(index >= 0 && index < size) { "index within bounds" } return elementAt(index) } + @Law inline fun Array.elementAtOrNullLaw(index: Int): E? = elementAtOrNull(index).post({ (it == null) == (index < 0 && index >= size) }) { "null iff out of bounds" } + @Law inline fun Collection.firstLaw(): E { pre(size >= 1) { "not empty" } return first() } + @Law inline fun Array.firstLawWithPredicate(predicate: (x: E) -> Boolean): E { pre(size >= 1) { "not empty" } return first(predicate) } + @Law inline fun Array.firstOrNullLaw(): E? = firstOrNull().post({ (it == null) == (this.size <= 0) }) { "null iff empty" } + @Law inline fun Array.lastLaw(): E { pre(size >= 1) { "not empty" } return last() } + @Law inline fun Array.lastLaw(predicate: (x: E) -> Boolean): E { pre(size >= 1) { "not empty" } return last(predicate) } + @Law inline fun Array.lastOrNullLaw(): E? = lastOrNull().post({ (it == null) == (this.size <= 0) }) { "null iff empty" } @@ -96,6 +111,7 @@ object ArrayLaws { pre(size == 1) { "size should be exactly 1" } return single() } + @Law inline fun Array.singleOrNullLaw(): E? = singleOrNull().post({ (it == null) == (this.size != 1) }) { "null iff size is not 1" } @@ -105,16 +121,19 @@ object ArrayLaws { indexOf(element).post({ if (this.size <= 0) (it == -1) else (it >= -1) }) { "bounds for indexOf" } + @Law inline fun Array.lastIndexOfLaw(element: E): Int = lastIndexOf(element).post({ if (this.size <= 0) (it == -1) else (it >= -1) }) { "bounds for lastIndexOf" } + @Law inline fun Array.indexOfFirstLaw(predicate: (x: E) -> Boolean): Int = indexOfFirst(predicate).post({ if (this.size <= 0) (it == -1) else (it >= -1) }) { "bounds for indexOfFirst" } + @Law inline fun Array.indexOfLastLaw(predicate: (x: E) -> Boolean): Int = indexOfLast(predicate).post({ if (this.size <= 0) (it == -1) else (it >= -1) }) { @@ -126,6 +145,7 @@ object ArrayLaws { pre(size > 0) { "not empty" } return random() } + @Law inline fun Array.randomOrNullLaw(): T? = randomOrNull().post({ (it == null) == (this.size <= 0) }) { "null iff empty" } @@ -133,15 +153,19 @@ object ArrayLaws { @Law inline fun Array.filterLaw(predicate: (E) -> Boolean): List = filter(predicate).post({ it.size <= this.size }) { "bounds after filter" } + @Law inline fun Array.filterNotLaw(predicate: (E) -> Boolean): List = filterNot(predicate).post({ it.size <= this.size }) { "bounds after filter" } + @Law inline fun Array.filterNotNullLaw(): List = filterNotNull().post({ it.size <= this.size }) { "bounds after filter" } + @Law inline fun Array.filterIndexedLaw(predicate: (Int, E) -> Boolean): List = filterIndexed(predicate).post({ it.size <= this.size }) { "bounds after filter" } + @Law inline fun Array<*>.filterIsInstanceLaw(): List = filterIsInstance().post({ it.size <= this.size }) { "bounds after filter" } @@ -149,6 +173,7 @@ object ArrayLaws { @Law inline fun Array.distinctLaw(): List = distinct().post({ it.size <= this.size }) { "size bounded by original " } + @Law inline fun Array.distinctByLaw(selector: (T) -> K): List = distinctBy(selector).post({ it.size <= this.size }) { "size bounded by original " } @@ -156,6 +181,7 @@ object ArrayLaws { @Law inline fun Array.mapLaw(transform: (A) -> B): List = map(transform).post({ it.size == this.size }) { "size remains after map" } + @Law inline fun Array.mapIndexedLaw(transform: (Int, A) -> B): List = mapIndexed(transform).post({ it.size == this.size }) { "size remains after map" } @@ -163,6 +189,7 @@ object ArrayLaws { @Law inline fun Array.mapNotNullLaw(transform: (A) -> B?): List = mapNotNull(transform).post({ it.size <= this.size }) { "size bounded by original" } + @Law inline fun Array.mapIndexedNotNullLaw(transform: (Int, A) -> B?): List = mapIndexedNotNull(transform).post({ it.size == this.size }) { "size bounded by original" } @@ -172,9 +199,11 @@ object ArrayLaws { intersect(other).post({ it.size <= this.size && it.size <= other.size }) { "bounds for intersection" } + @Law inline fun Array.subtractLaw(other: Collection): Set = subtract(other).post({ it.size <= this.size }) { "bounds for subtraction" } + @Law inline fun Array.unionLaw(other: Collection): Set = union(other).post({ it.size >= this.size && it.size >= other.size }) { @@ -186,21 +215,25 @@ object ArrayLaws { pre(this.size >= 1) { "element #1 available" } return component1() } + @Law inline fun Array.component2Law(): E { pre(this.size >= 2) { "element #2 available" } return component2() } + @Law inline fun Array.component3Law(): E { pre(this.size >= 3) { "element #3 available" } return component3() } + @Law inline fun Array.component4Law(): E { pre(this.size >= 4) { "element #4 available" } return component4() } + @Law inline fun Array.component5Law(): E { pre(this.size >= 5) { "element #5 available" } @@ -213,12 +246,15 @@ object ArrayConversionsLaws { @Law inline fun Array>.toMapLaw(): Map = toMap().post({ it.size <= this.size }) { "size bounded by array" } + @Law inline fun Array.associateLaw(transform: (T) -> Pair): Map = associate(transform).post({ it.size <= this.size }) { "size bounded by array" } + @Law inline fun Array.associateByLaw(keySelector: (T) -> K): Map = associateBy(keySelector).post({ it.size <= this.size }) { "size bounded by array" } + @Law inline fun Array.associateWithLaw(valueSelector: (K) -> T): Map = associateWith(valueSelector).post({ it.size <= this.size }) { "size bounded by array" } @@ -226,6 +262,7 @@ object ArrayConversionsLaws { @Law inline fun Array.toListLaw(): List = toList().post({ it.size == this.size }) { "size remains after converstion to list" } + @Law inline fun Array.toSetLaw(): Set = toSet().post({ it.size < this.size }) { "size bounded by original size" } @@ -237,14 +274,17 @@ object CharArrayLaws { inline fun constructorLaw(size: Int, noinline init: (Int) -> Char): CharArray { return CharArray(size, init).post({ it.size == size }) { "size is the given one" } } + @Law inline fun charArrayOfLaw(vararg elements: Char): CharArray = charArrayOf(*elements).post({ it.size == elements.size }) { "literal size" } + @Law inline fun CharArray.getLaw(index: Int): Char { pre(index >= 0 && index < size) { "index within bounds" } return get(index) } + @Law inline fun CharArray.setLaw(index: Int, value: Char) { pre(index >= 0 && index < size) { "index within bounds" } @@ -258,14 +298,17 @@ object BooleanArrayLaws { inline fun constructorLaw(size: Int, noinline init: (Int) -> Boolean): BooleanArray { return BooleanArray(size, init).post({ it.size == size }) { "size is the given one" } } + @Law inline fun booleanArrayOfLaw(vararg elements: Boolean): BooleanArray = booleanArrayOf(*elements).post({ it.size == elements.size }) { "literal size" } + @Law inline fun BooleanArray.getLaw(index: Int): Boolean { pre(index >= 0 && index < size) { "index within bounds" } return get(index) } + @Law inline fun BooleanArray.setLaw(index: Int, value: Boolean) { pre(index >= 0 && index < size) { "index within bounds" } @@ -279,14 +322,17 @@ object ByteArrayLaws { inline fun constructorLaw(size: Int, noinline init: (Int) -> Byte): ByteArray { return ByteArray(size, init).post({ it.size == size }) { "size is the given one" } } + @Law inline fun byteArrayOfLaw(vararg elements: Byte): ByteArray = byteArrayOf(*elements).post({ it.size == elements.size }) { "literal size" } + @Law inline fun ByteArray.getLaw(index: Int): Byte { pre(index >= 0 && index < size) { "index within bounds" } return get(index) } + @Law inline fun ByteArray.setLaw(index: Int, value: Byte) { pre(index >= 0 && index < size) { "index within bounds" } @@ -300,14 +346,17 @@ object ShortArrayLaws { inline fun constructorLaw(size: Int, noinline init: (Int) -> Short): ShortArray { return ShortArray(size, init).post({ it.size == size }) { "size is the given one" } } + @Law inline fun shortArrayOfLaw(vararg elements: Short): ShortArray = shortArrayOf(*elements).post({ it.size == elements.size }) { "literal size" } + @Law inline fun ShortArray.getLaw(index: Int): Short { pre(index >= 0 && index < size) { "index within bounds" } return get(index) } + @Law inline fun ShortArray.setLaw(index: Int, value: Short) { pre(index >= 0 && index < size) { "index within bounds" } @@ -321,14 +370,17 @@ object IntArrayLaws { inline fun constructorLaw(size: Int, noinline init: (Int) -> Int): IntArray { return IntArray(size, init).post({ it.size == size }) { "size is the given one" } } + @Law inline fun intArrayOfLaw(vararg elements: Int): IntArray = intArrayOf(*elements).post({ it.size == elements.size }) { "literal size" } + @Law inline fun IntArray.getLaw(index: Int): Int { pre(index >= 0 && index < size) { "index within bounds" } return get(index) } + @Law inline fun IntArray.setLaw(index: Int, value: Int) { pre(index >= 0 && index < size) { "index within bounds" } @@ -342,14 +394,17 @@ object LongArrayLaws { inline fun constructorLaw(size: Int, noinline init: (Int) -> Long): LongArray { return LongArray(size, init).post({ it.size == size }) { "size is the given one" } } + @Law inline fun longArrayOfLaw(vararg elements: Long): LongArray = longArrayOf(*elements).post({ it.size == elements.size }) { "literal size" } + @Law inline fun LongArray.getLaw(index: Int): Long { pre(index >= 0 && index < size) { "index within bounds" } return get(index) } + @Law inline fun LongArray.setLaw(index: Int, value: Long) { pre(index >= 0 && index < size) { "index within bounds" } @@ -363,14 +418,17 @@ object FloatArrayLaws { inline fun constructorLaw(size: Int, noinline init: (Int) -> Float): FloatArray { return FloatArray(size, init).post({ it.size == size }) { "size is the given one" } } + @Law inline fun floatArrayOfLaw(vararg elements: Float): FloatArray = floatArrayOf(*elements).post({ it.size == elements.size }) { "literal size" } + @Law inline fun FloatArray.getLaw(index: Int): Float { pre(index >= 0 && index < size) { "index within bounds" } return get(index) } + @Law inline fun FloatArray.setLaw(index: Int, value: Float) { pre(index >= 0 && index < size) { "index within bounds" } @@ -384,14 +442,17 @@ object DoubleArrayLaws { inline fun constructorLaw(size: Int, noinline init: (Int) -> Double): DoubleArray { return DoubleArray(size, init).post({ it.size == size }) { "size is the given one" } } + @Law inline fun doubleArrayOfLaw(vararg elements: Double): DoubleArray = doubleArrayOf(*elements).post({ it.size == elements.size }) { "literal size" } + @Law inline fun DoubleArray.getLaw(index: Int): Double { pre(index >= 0 && index < size) { "index within bounds" } return get(index) } + @Law inline fun DoubleArray.setLaw(index: Int, value: Double) { pre(index >= 0 && index < size) { "index within bounds" } diff --git a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/CharAndString.kt b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/CharAndString.kt index 8346064d..4cd88e72 100644 --- a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/CharAndString.kt +++ b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/CharAndString.kt @@ -12,12 +12,15 @@ import arrow.analysis.pre object CharSequenceLaws { @Law inline fun CharSequence.lengthLaw(): Int = length.post({ it >= 0 }) { "length is non-negative" } + @Law inline fun CharSequence.countLaw(): Int = count().post({ it == this.length }) { "count is length" } + @Law inline fun CharSequence.countLaw(predicate: (Char) -> Boolean): Int = count(predicate).post({ it <= this.length }) { "count bounded by length" } + @Law inline fun CharSequence.lastIndexLaw(): Int = lastIndex.post({ it == length - 1 }) { "last index is length - 1" } @@ -25,12 +28,15 @@ object CharSequenceLaws { @Law inline fun CharSequence.isEmptyLaw(): Boolean = isEmpty().post({ it == (length <= 0) }) { "empty when length is 0" } + @Law inline fun CharSequence.noneLaw(): Boolean = none().post({ it == (length <= 0) }) { "none when length is 0" } + @Law inline fun CharSequence.isNotEmptyLaw(): Boolean = isNotEmpty().post({ it == (length > 0) }) { "not empty when length is > 0" } + @Law inline fun CharSequence?.isNullOrEmptyLaw(): Boolean = isNullOrEmpty().post({ it == ((this == null) || (this.length <= 0)) }) { @@ -48,34 +54,41 @@ object CharSequenceLaws { pre(index >= 0 && index < length) { "index within bounds" } return elementAt(index) } + @Law inline fun CharSequence.elementAtOrNullLaw(index: Int): Char? = elementAtOrNull(index).post({ (it == null) == (index < 0 && index >= length) }) { "null iff out of bounds" } + @Law inline fun CharSequence.firstLaw(): Char { pre(length >= 1) { "not empty" } return first() } + @Law inline fun CharSequence.firstLawWithPredicate(predicate: (x: Char) -> Boolean): Char { pre(length >= 1) { "not empty" } return first(predicate) } + @Law inline fun CharSequence.firstOrNullLaw(): Char? = firstOrNull().post({ (it == null) == (this.length <= 0) }) { "null iff empty" } + @Law inline fun CharSequence.lastLaw(): Char { pre(length >= 1) { "not empty" } return last() } + @Law inline fun CharSequence.lastLaw(predicate: (x: Char) -> Boolean): Char { pre(length >= 1) { "not empty" } return last(predicate) } + @Law inline fun CharSequence.lastOrNullLaw(): Char? = lastOrNull().post({ (it == null) == (this.length <= 0) }) { "null iff empty" } @@ -85,6 +98,7 @@ object CharSequenceLaws { pre(length == 1) { "length should be exactly 1" } return single() } + @Law inline fun CharSequence.singleOrNullLaw(): Char? = singleOrNull().post({ (it == null) == (this.length != 1) }) { "null iff length is not 1" } @@ -96,44 +110,49 @@ object CharSequenceLaws { }) { "bounds for indexOf" } + @Law inline fun CharSequence.indexOfLawString( element: String, startIndex: Int, - ignoreCase: Boolean + ignoreCase: Boolean, ): Int = indexOf(element, startIndex, ignoreCase).post({ if (this.length <= 0) (it == -1) else (it >= -1) }) { "bounds for indexOf" } + @Law inline fun CharSequence.lastIndexOfLawChar( element: Char, startIndex: Int, - ignoreCase: Boolean + ignoreCase: Boolean, ): Int = lastIndexOf(element, startIndex, ignoreCase).post({ if (this.length <= 0) (it == -1) else (it >= -1) }) { "bounds for lastIndexOf" } + @Law inline fun CharSequence.lastIndexOfLawString( element: String, startIndex: Int, - ignoreCase: Boolean + ignoreCase: Boolean, ): Int = lastIndexOf(element, startIndex, ignoreCase).post({ if (this.length <= 0) (it == -1) else (it >= -1) }) { "bounds for lastIndexOf" } + @Law inline fun CharSequence.indexOfFirstLaw(predicate: (x: Char) -> Boolean): Int = indexOfFirst(predicate).post({ if (this.length <= 0) (it == -1) else (it >= -1) }) { "bounds for indexOfFirst" } + @Law inline fun CharSequence.indexOfLastLaw(predicate: (x: Char) -> Boolean): Int = indexOfLast(predicate).post({ if (this.length <= 0) (it == -1) else (it >= -1) }) { @@ -149,9 +168,11 @@ object CharSequenceLaws { @Law inline fun CharSequence.filterLaw(predicate: (Char) -> Boolean): CharSequence = filter(predicate).post({ it.length <= this.length }) { "bounds after filter" } + @Law inline fun CharSequence.filterNotLaw(predicate: (Char) -> Boolean): CharSequence = filterNot(predicate).post({ it.length <= this.length }) { "bounds after filter" } + @Law inline fun CharSequence.filterIndexedLaw(predicate: (Int, Char) -> Boolean): CharSequence = filterIndexed(predicate).post({ it.length <= this.length }) { "bounds after filter" } @@ -159,6 +180,7 @@ object CharSequenceLaws { @Law inline fun CharSequence.mapLaw(transform: (Char) -> B): List = map(transform).post({ it.size == this.length }) { "length remains after map" } + @Law inline fun CharSequence.mapIndexedLaw(transform: (Int, Char) -> B): List = mapIndexed(transform).post({ it.size == this.length }) { "length remains after map" } @@ -166,6 +188,7 @@ object CharSequenceLaws { @Law inline fun CharSequence.mapNotNullLaw(transform: (Char) -> B?): List = mapNotNull(transform).post({ it.size <= this.length }) { "length bounded by original" } + @Law inline fun CharSequence.mapIndexedNotNullLaw(transform: (Int, Char) -> B?): List = mapIndexedNotNull(transform).post({ it.size == this.length }) { "length bounded by original" } @@ -179,11 +202,13 @@ object CharSequenceLaws { "bounds for drop" } } + @Law inline fun CharSequence.takeLaw(n: Int): CharSequence { pre(n >= 0) { "n must be non-negative" } return take(n).post({ it.length <= this.length && it.length <= n }) { "bounds for take" } } + @Law inline fun CharSequence.dropLastLaw(n: Int): CharSequence { pre(n >= 0) { "n must be non-negative" } @@ -193,6 +218,7 @@ object CharSequenceLaws { "bounds for drop" } } + @Law inline fun CharSequence.takeLastLaw(n: Int): CharSequence { pre(n >= 0) { "n must be non-negative" } @@ -202,18 +228,23 @@ object CharSequenceLaws { @Law inline fun CharSequence.trimLaw(): CharSequence = trim().post({ it.length <= this.length }) { "trim may reduce the size" } + @Law inline fun CharSequence.trimLaw(vararg chars: Char): CharSequence = trim(*chars).post({ it.length <= this.length }) { "trim may reduce the size" } + @Law inline fun CharSequence.trimEndLaw(): CharSequence = trimEnd().post({ it.length <= this.length }) { "trim may reduce the size" } + @Law inline fun CharSequence.trimEndLaw(vararg chars: Char): CharSequence = trimEnd(*chars).post({ it.length <= this.length }) { "trim may reduce the size" } + @Law inline fun CharSequence.trimStartLaw(): CharSequence = trimStart().post({ it.length <= this.length }) { "trim may reduce the size" } + @Law inline fun CharSequence.trimStartLaw(vararg chars: Char): CharSequence = trimStart(*chars).post({ it.length <= this.length }) { "trim may reduce the size" } @@ -224,9 +255,11 @@ object CharSequenceConversionsLaws { @Law inline fun CharSequence.associateLaw(transform: (Char) -> Pair): Map = associate(transform).post({ it.size <= this.length }) { "length bounded by array" } + @Law inline fun CharSequence.associateByLaw(keySelector: (Char) -> K): Map = associateBy(keySelector).post({ it.size <= this.length }) { "length bounded by array" } + @Law inline fun CharSequence.associateWithLaw(valueSelector: (Char) -> T): Map = associateWith(valueSelector).post({ it.size <= this.length }) { "length bounded by array" } @@ -234,6 +267,7 @@ object CharSequenceConversionsLaws { @Law inline fun CharSequence.toListLaw(): List = toList().post({ it.size == this.length }) { "length remains after converstion to list" } + @Law inline fun CharSequence.toMutableListLaw(): List = toMutableList().post({ it.size == this.length }) { "length remains after converstion to list" } @@ -241,6 +275,7 @@ object CharSequenceConversionsLaws { @Law inline fun CharSequence.toSetLaw(): Set = toSet().post({ it.size < this.length }) { "length bounded by original length" } + @Law inline fun CharSequence.toHashSetLaw(): HashSet = toHashSet().post({ it.size < this.length }) { "length bounded by original length" } diff --git a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Collections.kt b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Collections.kt index f59e7023..a1274159 100644 --- a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Collections.kt +++ b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Collections.kt @@ -18,9 +18,11 @@ import arrow.analysis.pre object CollectionLaws { @Law inline fun Collection.sizeLaw(): Int = size.post({ it >= 0 }) { "size is non-negative" } + @Law inline fun Collection.countLaw(): Int = count().post({ it == this.size }) { "count is size" } + @Law inline fun Collection.countLaw(predicate: (E) -> Boolean): Int { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -30,17 +32,21 @@ object CollectionLaws { @Law inline fun Collection.isEmptyLaw(): Boolean = isEmpty().post({ it == (size <= 0) }) { "empty when size is 0" } + @Law inline fun Collection.noneLaw(): Boolean = none().post({ it == (size <= 0) }) { "none when size is 0" } + @Law inline fun Collection.isNotEmptyLaw(): Boolean = isNotEmpty().post({ it == (size > 0) }) { "not empty when size is > 0" } + @Law inline fun Collection?.isNullOrEmptyLaw(): Boolean = isNullOrEmpty().post({ it == ((this == null) || (this.size <= 0)) }) { "either null or size is 0" } + @Law inline fun Collection?.orEmptyLaw(): Collection = orEmpty().post({ if (this == null) (it.size == 0) else (it.size == this.size) }) { @@ -52,34 +58,41 @@ object CollectionLaws { pre(index >= 0 && index < size) { "index within bounds" } return elementAt(index) } + @Law inline fun Collection.elementAtOrNullLaw(index: Int): E? = elementAtOrNull(index).post({ (it == null) == (index < 0 && index >= size) }) { "null iff out of bounds" } + @Law inline fun Collection.firstLaw(): E { pre(size >= 1) { "not empty" } return first() } + @Law inline fun Collection.firstLawWithPredicate(predicate: (x: E) -> Boolean): E { pre(size >= 1) { "not empty" } return first(predicate) } + @Law inline fun Collection.firstOrNullLaw(): E? = firstOrNull().post({ (it == null) == (this.size <= 0) }) { "null iff empty" } + @Law inline fun Collection.lastLaw(): E { pre(size >= 1) { "not empty" } return last() } + @Law inline fun Collection.lastLaw(predicate: (x: E) -> Boolean): E { pre(size >= 1) { "not empty" } return last(predicate) } + @Law inline fun Collection.lastOrNullLaw(): E? = lastOrNull().post({ (it == null) == (this.size <= 0) }) { "null iff empty" } @@ -89,6 +102,7 @@ object CollectionLaws { pre(size == 1) { "size should be exactly 1" } return single() } + @Law inline fun Collection.singleOrNullLaw(): E? = singleOrNull().post({ (it == null) == (this.size != 1) }) { "null iff size is not 1" } @@ -98,11 +112,13 @@ object CollectionLaws { indexOf(element).post({ if (this.size <= 0) (it == -1) else (it >= -1) }) { "bounds for indexOf" } + @Law inline fun Collection.lastIndexOfLaw(element: E): Int = lastIndexOf(element).post({ if (this.size <= 0) (it == -1) else (it >= -1) }) { "bounds for lastIndexOf" } + @Law inline fun Collection.indexOfFirstLaw(predicate: (x: E) -> Boolean): Int { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -110,6 +126,7 @@ object CollectionLaws { "bounds for indexOfFirst" } } + @Law inline fun Collection.indexOfLastLaw(predicate: (x: E) -> Boolean): Int { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -123,6 +140,7 @@ object CollectionLaws { pre(size > 0) { "not empty" } return random() } + @Law inline fun Collection.randomOrNullLaw(): T? = randomOrNull().post({ (it == null) == (this.size <= 0) }) { "null iff empty" } @@ -133,6 +151,7 @@ object CollectionLaws { unzip().post({ it.first.size == this.size && it.second.size == this.size }) { "size remains after unzip" } + @Law inline fun Collection.zipLaw(other: Collection): List> { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -140,21 +159,24 @@ object CollectionLaws { "size bounded by the smallest" } } + @Law inline fun Collection.zipLaw( other: Collection, - transform: (a: T, b: R) -> V + transform: (a: T, b: R) -> V, ): List { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return zip(other, transform).post({ it.size <= this.size && it.size <= other.size }) { "size bounded by the smallest" } } + @Law inline fun Collection.zipWithNextLaw(): List> = zipWithNext().post({ if (this.size < 2) (it.size == 0) else (it.size == this.size - 1) }) { "size is one less" } + @Law inline fun Collection.zipWithNextLaw(transform: (a: T, b: T) -> V): List { doNotLookAtArgumentsWhen(size < 2) { "empty lists have no elements" } @@ -173,16 +195,19 @@ object CollectionLaws { "bounds for drop" } } + @Law inline fun Collection.dropWhileLaw(predicate: (E) -> Boolean): List { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return dropWhile(predicate).post({ it.size <= this.size }) { "bounds for dropWhile" } } + @Law inline fun Collection.takeLaw(n: Int): List { pre(n >= 0) { "n must be non-negative" } return take(n).post({ it.size <= this.size && it.size <= n }) { "bounds for take" } } + @Law inline fun Collection.takeWhileLaw(predicate: (E) -> Boolean): List { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -194,19 +219,23 @@ object CollectionLaws { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return filter(predicate).post({ it.size <= this.size }) { "bounds after filter" } } + @Law inline fun Collection.filterNotLaw(predicate: (E) -> Boolean): List { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return filterNot(predicate).post({ it.size <= this.size }) { "bounds after filter" } } + @Law inline fun Collection.filterNotNullLaw(): List = filterNotNull().post({ it.size <= this.size }) { "bounds after filter" } + @Law inline fun Collection.filterIndexedLaw(predicate: (Int, E) -> Boolean): List { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return filterIndexed(predicate).post({ it.size <= this.size }) { "bounds after filter" } } + @Law inline fun Collection<*>.filterIsInstanceLaw(): List = filterIsInstance().post({ it.size <= this.size }) { "bounds after filter" } @@ -214,6 +243,7 @@ object CollectionLaws { @Law inline fun Collection.distinctLaw(): List = distinct().post({ it.size <= this.size }) { "size bounded by original " } + @Law inline fun Collection.distinctByLaw(selector: (T) -> K): List { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -223,6 +253,7 @@ object CollectionLaws { @Law inline fun Collection.plusLaw(element: E): List = plus(element).post({ it.size == this.size + 1 }) { "size increases by 1" } + @Law inline fun Collection.plusLawWithElements(elements: Collection): List = plus(elements).post({ it.size == this.size + elements.size }) { @@ -234,6 +265,7 @@ object CollectionLaws { minus(element).post({ it.size >= this.size - 1 && it.size <= this.size }) { "size may decrease by 1" } + @Law inline fun Collection.minusLawWithElements(elements: Collection): List = minus(elements).post({ it.size >= this.size - elements.size && it.size <= this.size }) { @@ -244,12 +276,15 @@ object CollectionLaws { @Law inline fun Collection.reversedLaw(): List = reversed().post({ it.size == this.size }) { "size remains after reversal" } + @Law inline fun > Collection.sortedLaw(): List = sorted().post({ it.size == this.size }) { "size remains after sorting" } + @Law inline fun > Collection.sortedDescendingLaw(): List = sortedDescending().post({ it.size == this.size }) { "size remains after sorting" } + @Law inline fun > Collection.sortedByLaw( crossinline selector: (T) -> R? @@ -257,6 +292,7 @@ object CollectionLaws { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return sortedBy(selector).post({ it.size == this.size }) { "size remains after sorting" } } + @Law inline fun > Collection.sortedByDescendingLaw( crossinline selector: (T) -> R? @@ -266,6 +302,7 @@ object CollectionLaws { "size remains after sorting" } } + @Law inline fun Collection.sortedWithLaw(comparator: Comparator): List = sortedWith(comparator).post({ it.size == this.size }) { "size remains after sorting" } @@ -279,6 +316,7 @@ object CollectionLaws { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return map(transform).post({ it.size == this.size }) { "size remains after map" } } + @Law inline fun Collection.mapIndexedLaw(transform: (Int, A) -> B): List { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -290,6 +328,7 @@ object CollectionLaws { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return mapNotNull(transform).post({ it.size <= this.size }) { "size bounded by original" } } + @Law inline fun Collection.mapIndexedNotNullLaw(transform: (Int, A) -> B?): List { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -303,6 +342,7 @@ object CollectionLaws { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return forEach(action) } + @Law inline fun Collection.forEachIndexedLaw(action: (Int, A) -> Unit): Unit { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -314,6 +354,7 @@ object CollectionLaws { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return onEach(action).post({ it.size == size }) { "onEach does nothing" } } + @Law inline fun > C.onEachIndexedLaw(action: (Int, A) -> Unit): C { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -329,6 +370,7 @@ object CollectionLaws { "size of empty list" } } + @Law inline fun Collection.flatMapIndexedLaw( transform: (index: Int, A) -> Iterable @@ -340,6 +382,7 @@ object CollectionLaws { "size of empty list" } } + @Law inline fun Collection>.flattenLaw(): List = flatten().post({ if (size <= 0) it.size == 0 else /* true means no info */ true }) { @@ -352,9 +395,11 @@ object CollectionLaws { intersect(other).post({ it.size <= this.size && it.size <= other.size }) { "bounds for intersection" } + @Law inline fun Collection.subtractLaw(other: Collection): Set = subtract(other).post({ it.size <= this.size }) { "bounds for subtraction" } + @Law inline fun Collection.unionLaw(other: Collection): Set = union(other).post({ it.size >= this.size && it.size >= other.size }) { @@ -369,9 +414,11 @@ object CollectionLaws { "true for empty lists" } } + @Law inline fun Collection.anyLaw(): Boolean = any().post({ it == (size > 0) }) { "any means at least one element" } + @Law inline fun Collection.anyLaw(predicate: (T) -> Boolean): Boolean { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -391,16 +438,19 @@ object ListLaws { pre(index >= 0 && index < size) { "index within bounds" } return get(index) } + @Law inline fun List.elementAtLaw(index: Int): E { pre(index >= 0 && index < size) { "index within bounds" } return elementAt(index) } + @Law inline fun List.getOrNullLaw(index: Int): E? = getOrNull(index).post({ (it == null) == (index < 0 && index >= size) }) { "null iff out of bounds" } + @Law inline fun List.elementAtOrNullLaw(index: Int): E? = elementAtOrNull(index).post({ (it == null) == (index < 0 && index >= size) }) { @@ -412,19 +462,23 @@ object ListLaws { pre(size >= 1) { "not empty" } return first() } + @Law inline fun List.firstOrNullLaw(): E? = firstOrNull().post({ (it == null) == (this.size <= 0) }) { "null iff empty" } + @Law inline fun List.lastLaw(): E { pre(size >= 1) { "not empty" } return last() } + @Law inline fun List.lastLaw(predicate: (x: E) -> Boolean): E { pre(size >= 1) { "not empty" } return last(predicate) } + @Law inline fun List.lastOrNullLaw(): E? = lastOrNull().post({ (it == null) == (this.size <= 0) }) { "null iff empty" } @@ -434,6 +488,7 @@ object ListLaws { pre(size == 1) { "size should be exactly 1" } return single() } + @Law inline fun List.singleOrNullLaw(): E? = singleOrNull().post({ (it == null) == (this.size != 1) }) { "null iff size is not 1" } @@ -443,14 +498,17 @@ object ListLaws { indexOf(element).post({ if (this.size <= 0) (it == -1) else (it >= -1) }) { "bounds for indexOf" } + @Law inline fun List.lastIndexOfLaw(element: E): Int = lastIndexOf(element).post({ if (this.size <= 0) (it == -1) else (it >= -1) }) { "bounds for lastIndexOf" } + @Law inline fun List.lastIndexLaw(): Int = lastIndex.post({ it == size - 1 }) { "last index is size - 1" } + @Law inline fun List.indexOfFirstLaw(predicate: (x: E) -> Boolean): Int { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -458,6 +516,7 @@ object ListLaws { "bounds for indexOfFirst" } } + @Law inline fun List.indexOfLastLaw(predicate: (x: E) -> Boolean): Int { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -469,20 +528,25 @@ object ListLaws { @Law inline fun emptyListLaw(): List = emptyList().post({ it.size == 0 }) { "empty list is empty" } + @Law inline fun emptyListOfLaw(): List = listOf().post({ it.size == 0 }) { "empty list is empty" } + @Law inline fun listOfNotNullLaw(element: E?): List = listOfNotNull(element).post({ if (element == null) (it.size == 0) else (it.size == 1) }) { "empty iff element is null" } + @Law inline fun singletonListOfLaw(element: E): List = listOf(element).post({ it.size == 1 }) { "singleton list has size 1" } + @Law inline fun listOfLaw(vararg elements: E): List = listOf(*elements).post({ it.size == elements.size }) { "literal size" } + @Law inline fun listOfNotNullLaw(vararg elements: E?): List = listOfNotNull(*elements).post({ it.size <= elements.size }) { "bounded by the literal" } @@ -490,6 +554,7 @@ object ListLaws { @Law inline fun emptyMutableListLaw(): List = mutableListOf().post({ it.size == 0 }) { "empty list is empty" } + @Law inline fun mutableListOfLaw(vararg elements: E): MutableList = mutableListOf(*elements).post({ it.size == elements.size }) { "literal size" } @@ -509,21 +574,25 @@ object ListLaws { pre(this.size >= 1) { "element #1 available" } return component1() } + @Law inline fun List.component2Law(): E { pre(this.size >= 2) { "element #2 available" } return component2() } + @Law inline fun List.component3Law(): E { pre(this.size >= 3) { "element #3 available" } return component3() } + @Law inline fun List.component4Law(): E { pre(this.size >= 4) { "element #4 available" } return component4() } + @Law inline fun List.component5Law(): E { pre(this.size >= 5) { "element #5 available" } @@ -540,6 +609,7 @@ object ListLaws { "bounds for drop" } } + @Law inline fun List.takeLastLaw(n: Int): List { pre(n >= 0) { "n must be non-negative" } @@ -559,17 +629,21 @@ object SetLaws { @Law inline fun emptySetLaw(): Set = emptySet().post({ it.size == 0 }) { "empty set is empty" } + @Law inline fun emptySetOfLaw(): Set = setOf().post({ it.size == 0 }) { "empty set is empty" } + @Law inline fun setOfNotNullLaw(element: E?): Set = setOfNotNull(element).post({ if (element == null) (it.size == 0) else (it.size == 1) }) { "empty iff element is null" } + @Law inline fun setOfLaw(vararg elements: E): Set = setOf(*elements).post({ it.size <= elements.size }) { "bounded by the literal" } + @Law inline fun setOfNotNullLaw(vararg elements: E?): Set = setOfNotNull(*elements).post({ it.size <= elements.size }) { "bounded by the literal" } @@ -577,6 +651,7 @@ object SetLaws { @Law inline fun emptyMutableSetOfLaw(): MutableSet = mutableSetOf().post({ it.size == 0 }) { "empty set is empty" } + @Law inline fun mutableSetOfLaw(vararg elements: E): MutableSet = mutableSetOf(*elements).post({ it.size <= elements.size }) { "bounded by the literal" } @@ -592,17 +667,21 @@ object SetLaws { object MapLaws { @Law inline fun Map.sizeLaw(): Int = size.post({ it >= 0 }) { "size is non-negative" } + @Law inline fun Map.isEmptyLaw(): Boolean = isEmpty().post({ it == (size <= 0) }) { "empty when size is 0" } + @Law inline fun Map.isNotEmptyLaw(): Boolean = isNotEmpty().post({ it == (size > 0) }) { "not empty when size is > 0" } + @Law inline fun Map?.isNullOrEmptyLaw(): Boolean = isNullOrEmpty().post({ it == ((this == null) || (this.size <= 0)) }) { "either null or size is 0" } + @Law inline fun Map?.orEmptyLaw(): Map = orEmpty().post({ if (this == null) (it.size == 0) else (it.size == this.size) }) { @@ -612,9 +691,11 @@ object MapLaws { @Law inline fun Map.keysLaw(): Set = keys.post({ it.size == this.size }) { "size of keys remains" } + @Law inline fun Map.valuesLaw(): Collection = values.post({ it.size == this.size }) { "size of values remains" } + @Law inline fun Map.entriesLaw(): Set> = entries.post({ it.size == this.size }) { "size of entries remains" } @@ -622,9 +703,11 @@ object MapLaws { @Law inline fun emptyMapLaw(): Map = emptyMap().post({ it.size == 0 }) { "empty map is empty" } + @Law inline fun emptyMapOfLaw(): Map = mapOf().post({ it.size == 0 }) { "empty map is empty" } + @Law inline fun mapOfLaw(vararg elements: Pair): Map = mapOf(*elements).post({ it.size <= elements.size }) { "literal size" } @@ -632,6 +715,7 @@ object MapLaws { @Law inline fun emptyMutableMapLaw(): Map = mutableMapOf().post({ it.size == 0 }) { "empty map is empty" } + @Law inline fun mutableMapOfLaw(vararg elements: Pair): MutableMap = mutableMapOf(*elements).post({ it.size <= elements.size }) { "literal size" } @@ -641,6 +725,7 @@ object MapLaws { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return mapValues(transform).post({ it.size == this.size }) { "size remains after mapValues" } } + @Law inline fun Map.mapKeysLaw(transform: (Map.Entry) -> R): Map { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -652,16 +737,19 @@ object MapLaws { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return filter(predicate).post({ it.size <= this.size }) { "size bounded after filter" } } + @Law inline fun Map.filterNotLaw(predicate: (Map.Entry) -> Boolean): Map { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return filterNot(predicate).post({ it.size <= this.size }) { "size bounded after filter" } } + @Law inline fun Map.filterValuesLaw(predicate: (V) -> Boolean): Map { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return filterValues(predicate).post({ it.size <= this.size }) { "size bounded after filter" } } + @Law inline fun Map.filterKeysLaw(predicate: (K) -> Boolean): Map { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -671,11 +759,13 @@ object MapLaws { @Law inline fun Map.plusLaw(pair: Pair): Map = plus(pair).post({ it.size <= this.size + 1 }) { "size may increase by 1" } + @Law inline fun Map.plusLawWithElements(pairs: Collection>): Map = plus(pairs).post({ it.size <= this.size + pairs.size }) { "size may increase by size of the collection" } + @Law inline fun Map.plusLawWithMap(map: Map): Map = plus(map).post({ it.size <= this.size + map.size }) { "size may increase by size of the map" } @@ -685,6 +775,7 @@ object MapLaws { minus(key).post({ it.size <= this.size && it.size >= this.size - 1 }) { "size may decrease by 1" } + @Law inline fun Map.minusLawWithElements(keys: Collection): Map = minus(keys).post({ it.size <= this.size && it.size >= this.size - keys.size }) { @@ -697,6 +788,7 @@ object MapEntryLaws { @Law inline fun Map.Entry.component1Law(): K = component1().post({ it == this.key }) { "1st component is key" } + @Law inline fun Map.Entry.component2Law(): V = component2().post({ it == this.value }) { "2nd component is value" } @@ -707,16 +799,19 @@ object CollectionConversionsLaws { @Law inline fun Collection>.toMapLaw(): Map = toMap().post({ it.size <= this.size }) { "size bounded by collection" } + @Law inline fun Collection.associateLaw(transform: (T) -> Pair): Map { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return associate(transform).post({ it.size <= this.size }) { "size bounded by collection" } } + @Law inline fun Collection.associateByLaw(keySelector: (T) -> K): Map { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } return associateBy(keySelector).post({ it.size <= this.size }) { "size bounded by collection" } } + @Law inline fun Collection.associateWithLaw(valueSelector: (K) -> T): Map { doNotLookAtArgumentsWhen(isEmpty()) { "empty lists have no elements" } @@ -728,6 +823,7 @@ object CollectionConversionsLaws { @Law inline fun Collection.toListLaw(): List = toList().post({ it.size == this.size }) { "size remains after converstion to list" } + @Law inline fun Collection.toSetLaw(): Set = toSet().post({ it.size < this.size }) { "size bounded by original size" } diff --git a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Math.kt b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Math.kt index 7d4fe1cb..6af984ac 100644 --- a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Math.kt +++ b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Math.kt @@ -19,36 +19,43 @@ object MathLaws { absoluteValue.post({ it >= 0 && (if (this >= 0) it == this else it == -this) }) { "absolute value is non-negative + definition" } + @Law inline fun Long.absoluteValueLaw(): Long = absoluteValue.post({ it >= 0L && (if (this >= 0L) it == this else it == -this) }) { "absolute value is non-negative + definition" } + @Law inline fun Float.absoluteValueLaw(): Float = absoluteValue.post({ it >= 0.0F && (if (this >= 0.0F) it == this else it == -this) }) { "absolute value is non-negative + definition" } + @Law inline fun Double.absoluteValueLaw(): Double = absoluteValue.post({ it >= 0.0 && (if (this >= 0.0) it == this else it == -this) }) { "absolute value is non-negative + definition" } + @Law inline fun absLaw(x: Int): Int = abs(x).post({ it >= 0 && (if (x >= 0) it == x else it == -x) }) { "absolute value is non-negative + definition" } + @Law inline fun absLaw(x: Long): Long = abs(x).post({ it >= 0L && (if (x >= 0L) it == x else it == -x) }) { "absolute value is non-negative + definition" } + @Law inline fun absLaw(x: Float): Float = abs(x).post({ it >= 0.0F && (if (x >= 0.0F) it == x else it == -x) }) { "absolute value is non-negative + definition" } + @Law inline fun absLaw(x: Double): Double = abs(x).post({ it >= 0.0 && (if (x >= 0.0) it == x else it == -x) }) { @@ -68,6 +75,7 @@ object MathLaws { }) { "sign bounds + definition" } + @Law inline fun Long.signLaw(): Int = sign.post({ @@ -81,6 +89,7 @@ object MathLaws { }) { "sign bounds + definition" } + @Law inline fun Double.signLaw(): Double = sign.post({ @@ -94,6 +103,7 @@ object MathLaws { }) { "sign bounds + definition" } + @Law inline fun Float.signLaw(): Float = sign.post({ @@ -121,6 +131,7 @@ object MathLaws { }) { "sign bounds + definition" } + @Law inline fun signTopLevelLaw(x: Float): Float = sign(x).post({ @@ -140,16 +151,19 @@ object MathLaws { max(a, b).post({ it >= a && it >= b && (if (a >= b) it == a else it == b) }) { "bounds for max + definition" } + @Law inline fun maxLaw(a: Long, b: Long): Long = max(a, b).post({ it >= a && it >= b && (if (a >= b) it == a else it == b) }) { "bounds for max + definition" } + @Law inline fun maxLaw(a: Float, b: Float): Float = max(a, b).post({ it >= a && it >= b && (if (a >= b) it == a else it == b) }) { "bounds for max + definition" } + @Law inline fun maxLaw(a: Double, b: Double): Double = max(a, b).post({ it >= a && it >= b && (if (a >= b) it == a else it == b) }) { @@ -161,16 +175,19 @@ object MathLaws { min(a, b).post({ it <= a && it <= b && (if (a <= b) it == a else it == b) }) { "bounds for min + definition" } + @Law inline fun minLaw(a: Long, b: Long): Long = min(a, b).post({ it <= a && it <= b && (if (a <= b) it == a else it == b) }) { "bounds for min + definition" } + @Law inline fun minLaw(a: Float, b: Float): Float = min(a, b).post({ it <= a && it <= b && (if (a <= b) it == a else it == b) }) { "bounds for min + definition" } + @Law inline fun minLaw(a: Double, b: Double): Double = min(a, b).post({ it <= a && it <= b && (if (a <= b) it == a else it == b) }) { diff --git a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Numbers.kt b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Numbers.kt index f7d6f988..f861ce3c 100644 --- a/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Numbers.kt +++ b/analysis/laws/src/commonMain/kotlin/arrow/analysis/laws/kotlin/Numbers.kt @@ -15,6 +15,7 @@ object ByteLaws { pre(other != 0) { "other is not zero" } return this / other } + @Law inline fun Byte.divLaw(other: Long): Long { pre(other != 0L) { "other is not zero" } @@ -41,6 +42,7 @@ object ShortLaws { pre(other != 0) { "other is not zero" } return this / other } + @Law inline fun Short.divLaw(other: Long): Long { pre(other != 0L) { "other is not zero" } @@ -67,6 +69,7 @@ object IntLaws { pre(other != 0) { "other is not zero" } return this / other } + @Law inline fun Int.divLaw(other: Long): Long { pre(other != 0L) { "other is not zero" } @@ -93,6 +96,7 @@ object LongLaws { pre(other != 0) { "other is not zero" } return this / other } + @Law inline fun Long.divLaw(other: Long): Long { pre(other != 0L) { "other is not zero" } diff --git a/analysis/types/src/commonMain/kotlin/arrow/analysis/RefinementDSL.kt b/analysis/types/src/commonMain/kotlin/arrow/analysis/RefinementDSL.kt index 00298bf3..2a434f16 100644 --- a/analysis/types/src/commonMain/kotlin/arrow/analysis/RefinementDSL.kt +++ b/analysis/types/src/commonMain/kotlin/arrow/analysis/RefinementDSL.kt @@ -30,21 +30,21 @@ public inline fun A.invariant(predicate: Predicate, msg: Messager): A { public annotation class Pre( val messages: Array, val formulae: Array, - val dependencies: Array + val dependencies: Array, ) @Target(AnnotationTarget.FUNCTION) public annotation class Post( val messages: Array, val formulae: Array, - val dependencies: Array + val dependencies: Array, ) @Target(AnnotationTarget.FUNCTION) public annotation class DoNotLookAtArguments( val messages: Array, val formulae: Array, - val dependencies: Array + val dependencies: Array, ) /** Annotation to flag ad-hoc refinements over third party functions */ diff --git a/build.gradle.kts b/build.gradle.kts index 9444c2e6..13a18b3f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,6 +13,7 @@ allprojects { repositories { mavenCentral() maven(url = "https://oss.sonatype.org/content/repositories/snapshots/") + mavenLocal() } group = property("projects.group").toString() diff --git a/gradle.properties b/gradle.properties index 79307a6a..1be933a0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,9 +18,11 @@ org.gradle.parallel=true # Kotlin configuration kotlin.incremental=true -kotlin.stdlib.default.dependency=false -kotlin.js.compiler=ir +kotlin.stdlib.default.dependency=true kotlin.mpp.stability.nowarn=true # Kotlin Test configuration #Parallelism needs to be set to 1 since the concurrent tests in arrow-effects become flaky otherwise kotlintest.parallelism=1 + +org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers + diff --git a/gradle/projects.libs.versions.toml b/gradle/projects.libs.versions.toml index af18a90d..1203cf65 100644 --- a/gradle/projects.libs.versions.toml +++ b/gradle/projects.libs.versions.toml @@ -1,21 +1,21 @@ [versions] -arrow = "1.2.0-RC" -arrowMeta = "1.6.2" -arrowGradleConfig = "0.12.0-rc.3" +arrow = "2.0.1" +arrowMeta = "1.6.3-alpha.2.12+2a2e25c" +arrowGradleConfig = "0.12.0-rc.26" classgraph = "4.8.157" -dokka = "1.8.10" +dokka = "2.0.0" junit = "5.9.2" junitLauncher = "1.9.2" -kotlin = "1.8.21" +kotlin = "2.1.10" kotest = "5.6.1" javaSmt = "3.14.3" javaCompileTesting = "0.21.0" apacheCommonsText = "1.10.0" sarif4k = "0.3.0" -kotlinBinaryCompatibilityValidator = "0.13.0" +kotlinBinaryCompatibilityValidator = "0.17.0" detekt = "1.22.0" kotlinxSerialization = "1.5.0" -ksp = "1.8.21-1.0.11" +ksp = "2.1.0-1.0.29" [libraries] arrowAnnotations = { module = "io.arrow-kt:arrow-annotations", version.ref = "arrow" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927a..a4b76b95 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae08049..707e21e6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c7873..f5feea6d 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,12 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +134,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +201,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +217,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f9..9b42019c 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +78,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/settings.gradle.kts b/settings.gradle.kts index 45ab96d6..12bc2564 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,6 +4,7 @@ pluginManagement { repositories { gradlePluginPortal() mavenCentral() + mavenLocal() } }