Search in sources :

Example 1 with LowerLevelDefinition

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

the class BallerinaPsiImplUtil method getAllEndpointsInResolvableScope.

@NotNull
public static List<IdentifierPSINode> getAllEndpointsInResolvableScope(@NotNull ScopeNode scope, int caretOffset) {
    List<IdentifierPSINode> results = new LinkedList<>();
    if (scope instanceof VariableContainer || scope instanceof CodeBlockScope || scope instanceof TopLevelDefinition || scope instanceof LowerLevelDefinition) {
        results.addAll(getAllEndpointsInScope(scope, caretOffset));
        ScopeNode context = scope.getContext();
        if (context != null) {
            results.addAll(getAllEndpointsInResolvableScope(context, caretOffset));
        }
    }
    return results;
}
Also used : VariableContainer(org.ballerinalang.plugins.idea.psi.scopes.VariableContainer) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) LowerLevelDefinition(org.ballerinalang.plugins.idea.psi.scopes.LowerLevelDefinition) ScopeNode(org.antlr.jetbrains.adaptor.psi.ScopeNode) LinkedList(java.util.LinkedList) CodeBlockScope(org.ballerinalang.plugins.idea.psi.scopes.CodeBlockScope) TopLevelDefinition(org.ballerinalang.plugins.idea.psi.scopes.TopLevelDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with LowerLevelDefinition

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

the class BallerinaPsiImplUtil method getAllXmlNamespacesInResolvableScope.

@NotNull
public static List<PsiElement> getAllXmlNamespacesInResolvableScope(@NotNull ScopeNode scope, int caretOffset) {
    List<PsiElement> results = new LinkedList<>();
    if (scope instanceof VariableContainer || scope instanceof CodeBlockScope || scope instanceof BallerinaFile) {
        results.addAll(getAllXmlNamespacesInScope(scope, caretOffset));
        ScopeNode context = scope.getContext();
        if (context != null) {
            results.addAll(getAllXmlNamespacesInResolvableScope(context, caretOffset));
        }
    } else if (scope instanceof ParameterContainer || scope instanceof TopLevelDefinition || scope instanceof LowerLevelDefinition) {
        ScopeNode context = scope.getContext();
        if (context != null) {
            results.addAll(getAllXmlNamespacesInResolvableScope(context, caretOffset));
        }
    }
    if (scope instanceof BallerinaFile) {
        PsiFile originalFile = ((BallerinaFile) scope).getOriginalFile();
        PsiDirectory containingPackage = originalFile.getParent();
        if (containingPackage == null) {
            return results;
        }
        PsiFile[] files = containingPackage.getFiles();
        for (PsiFile file : files) {
            // Do't check the current file again.
            if (file.equals(originalFile)) {
                continue;
            }
            Collection<NamespaceDeclarationNode> namespaceDeclarationNodes = PsiTreeUtil.findChildrenOfType(file, NamespaceDeclarationNode.class);
            for (NamespaceDeclarationNode namespaceDeclarationNode : namespaceDeclarationNodes) {
                PsiElement identifier = namespaceDeclarationNode.getNameIdentifier();
                if (identifier != null) {
                    results.add(identifier);
                }
            }
        }
    }
    return results;
}
Also used : BallerinaFile(org.ballerinalang.plugins.idea.psi.BallerinaFile) LinkedList(java.util.LinkedList) TopLevelDefinition(org.ballerinalang.plugins.idea.psi.scopes.TopLevelDefinition) VariableContainer(org.ballerinalang.plugins.idea.psi.scopes.VariableContainer) ParameterContainer(org.ballerinalang.plugins.idea.psi.scopes.ParameterContainer) NamespaceDeclarationNode(org.ballerinalang.plugins.idea.psi.NamespaceDeclarationNode) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) ScopeNode(org.antlr.jetbrains.adaptor.psi.ScopeNode) LowerLevelDefinition(org.ballerinalang.plugins.idea.psi.scopes.LowerLevelDefinition) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) CodeBlockScope(org.ballerinalang.plugins.idea.psi.scopes.CodeBlockScope) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LowerLevelDefinition

use of org.ballerinalang.plugins.idea.psi.scopes.LowerLevelDefinition 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)3 ScopeNode (org.antlr.jetbrains.adaptor.psi.ScopeNode)3 CodeBlockScope (org.ballerinalang.plugins.idea.psi.scopes.CodeBlockScope)3 LowerLevelDefinition (org.ballerinalang.plugins.idea.psi.scopes.LowerLevelDefinition)3 VariableContainer (org.ballerinalang.plugins.idea.psi.scopes.VariableContainer)3 NotNull (org.jetbrains.annotations.NotNull)3 IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)2 ParameterContainer (org.ballerinalang.plugins.idea.psi.scopes.ParameterContainer)2 TopLevelDefinition (org.ballerinalang.plugins.idea.psi.scopes.TopLevelDefinition)2 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 BallerinaFile (org.ballerinalang.plugins.idea.psi.BallerinaFile)1 NamespaceDeclarationNode (org.ballerinalang.plugins.idea.psi.NamespaceDeclarationNode)1 RestrictedScope (org.ballerinalang.plugins.idea.psi.scopes.RestrictedScope)1