All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.analysis.api.components.KtDataFlowInfoProvider.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1
Show newest version
/*
 * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package org.jetbrains.kotlin.analysis.api.components

import org.jetbrains.kotlin.analysis.api.KtAnalysisNonPublicApi
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
import org.jetbrains.kotlin.analysis.api.symbols.KtVariableLikeSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtReturnExpression

@KtAnalysisNonPublicApi
public abstract class KtDataFlowInfoProvider : KtAnalysisSessionComponent() {
    public abstract fun getExitPointSnapshot(statements: List): KtDataFlowExitPointSnapshot
}

@KtAnalysisNonPublicApi
public interface KtDataFlowInfoProviderMixin : KtAnalysisSessionMixIn {
    public fun getExitPointSnapshot(statements: List): KtDataFlowExitPointSnapshot = withValidityAssertion {
        return analysisSession.dataFlowInfoProvider.getExitPointSnapshot(statements)
    }
}

@KtAnalysisNonPublicApi
public class KtDataFlowExitPointSnapshot(
    /**
     * A default expression, if any.
     * @see [DefaultExpressionInfo] for more information.
     */
    public val defaultExpressionInfo: DefaultExpressionInfo?,

    /**
     * A list of [KtReturnExpression]s that return a value.
     */
    public val valuedReturnExpressions: List,

    /**
     * A common supertype of values returned in [valuedReturnExpressions].
     */
    public val returnValueType: KtType?,

    /**
     * `break` and `continue` jump expressions.
     * @see [hasJumps] for the definition of jumps.
     */
    public val loopJumpExpressions: List,

    /**
     * `true` if there are any control-flow statements that jump outside given statements.
     * Jumps include both loop jumps (`break` and `continue`) and `return`s.
     * Conditional blocks (`if`) and `throw`s are not considered as jumps.
     */
    public val hasJumps: Boolean,

    /**
     * `true` if next-executed instructions for the potential default expression and jump expressions are different.
     */
    public val hasEscapingJumps: Boolean,

    /**
     * `true` if there are jumps of different kinds (e.g., there is both a `break` and a `return`).
     */
    public val hasMultipleJumpKinds: Boolean,

    /**
     * `true` if two or more jumps have different next-executed instructions. Such as, there are both inner and outer loop `break`s.
     */
    public val hasMultipleJumpTargets: Boolean,

    /**
     * local variable reassignments found in given statements.
     */
    public val variableReassignments: List
) {
    /**
     * Represents a default expression (generally, a last given statement if it has a meaningful result type).
     * Expressions that always return [Nothing], such as `return`, `break`, `continue` or `throw`, cannot be default expressions.
     */
    public class DefaultExpressionInfo(
        /** The default expression. */
        public val expression: KtExpression,

        /** The default expression type. */
        public val type: KtType
    )

    /**
     * Represents a local variable reassignment.
     */
    public class VariableReassignment(
        /** The reassignment expression. */
        public val expression: KtExpression,

        /** Reassigned variable symbol. */
        public val variable: KtVariableLikeSymbol,

        /** `true` if the variable is both read and set (as in `x += y` or `x++`). */
        public val isAugmented: Boolean
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy