Search in sources :

Example 1 with RestrictedScope

use of org.ballerinalang.plugins.idea.psi.scopes.RestrictedScope in project ballerina by ballerina-lang.

the class BallerinaPsiImplUtil method getAllLocalVariablesInResolvableScope.

/**
 * Returns all local variables in provided scope and all parent contexts.
 *
 * @param scope
 * @param caretOffset
 * @return
 */
@NotNull
public static List<IdentifierPSINode> getAllLocalVariablesInResolvableScope(@NotNull ScopeNode scope, int caretOffset) {
    List<IdentifierPSINode> results = new LinkedList<>();
    if (scope instanceof VariableContainer || scope instanceof CodeBlockScope) {
        results.addAll(getAllLocalVariablesInScope(scope, caretOffset));
        ScopeNode context = scope.getContext();
        if (context != null && !(scope instanceof RestrictedScope)) {
            results.addAll(getAllLocalVariablesInResolvableScope(context, caretOffset));
        }
    } else if (scope instanceof ParameterContainer || scope instanceof LowerLevelDefinition) {
        ScopeNode context = scope.getContext();
        if (context != null) {
            results.addAll(getAllLocalVariablesInResolvableScope(context, caretOffset));
        }
    }
    return results;
}
Also used : VariableContainer(org.ballerinalang.plugins.idea.psi.scopes.VariableContainer) ParameterContainer(org.ballerinalang.plugins.idea.psi.scopes.ParameterContainer) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) RestrictedScope(org.ballerinalang.plugins.idea.psi.scopes.RestrictedScope) ScopeNode(org.antlr.jetbrains.adaptor.psi.ScopeNode) LowerLevelDefinition(org.ballerinalang.plugins.idea.psi.scopes.LowerLevelDefinition) LinkedList(java.util.LinkedList) CodeBlockScope(org.ballerinalang.plugins.idea.psi.scopes.CodeBlockScope) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LinkedList (java.util.LinkedList)1 ScopeNode (org.antlr.jetbrains.adaptor.psi.ScopeNode)1 IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)1 CodeBlockScope (org.ballerinalang.plugins.idea.psi.scopes.CodeBlockScope)1 LowerLevelDefinition (org.ballerinalang.plugins.idea.psi.scopes.LowerLevelDefinition)1 ParameterContainer (org.ballerinalang.plugins.idea.psi.scopes.ParameterContainer)1 RestrictedScope (org.ballerinalang.plugins.idea.psi.scopes.RestrictedScope)1 VariableContainer (org.ballerinalang.plugins.idea.psi.scopes.VariableContainer)1 NotNull (org.jetbrains.annotations.NotNull)1