Search in sources :

Example 1 with TopLevelDefinition

use of org.ballerinalang.plugins.idea.psi.scopes.TopLevelDefinition 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 TopLevelDefinition

use of org.ballerinalang.plugins.idea.psi.scopes.TopLevelDefinition 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)

Aggregations

LinkedList (java.util.LinkedList)2 ScopeNode (org.antlr.jetbrains.adaptor.psi.ScopeNode)2 CodeBlockScope (org.ballerinalang.plugins.idea.psi.scopes.CodeBlockScope)2 LowerLevelDefinition (org.ballerinalang.plugins.idea.psi.scopes.LowerLevelDefinition)2 TopLevelDefinition (org.ballerinalang.plugins.idea.psi.scopes.TopLevelDefinition)2 VariableContainer (org.ballerinalang.plugins.idea.psi.scopes.VariableContainer)2 NotNull (org.jetbrains.annotations.NotNull)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 IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)1 NamespaceDeclarationNode (org.ballerinalang.plugins.idea.psi.NamespaceDeclarationNode)1 ParameterContainer (org.ballerinalang.plugins.idea.psi.scopes.ParameterContainer)1