Search in sources :

Example 26 with IdentifierPSINode

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

the class ConnectorReference method resolve.

@Nullable
@Override
public PsiElement resolve() {
    IdentifierPSINode identifier = getElement();
    PsiElement parent = identifier.getParent();
    PackageNameNode packageNameNode = PsiTreeUtil.getChildOfType(parent, PackageNameNode.class);
    if (packageNameNode == null) {
        return resolveInCurrentPackage(identifier);
    } else {
        return resolveInPackage(packageNameNode, identifier);
    }
}
Also used : PackageNameNode(org.ballerinalang.plugins.idea.psi.PackageNameNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with IdentifierPSINode

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

the class ConnectorReference method getVariantsInPackage.

@NotNull
private List<LookupElement> getVariantsInPackage(@NotNull PackageNameNode packageNameNode) {
    List<LookupElement> results = new LinkedList<>();
    PsiElement resolvedElement = BallerinaPsiImplUtil.resolvePackage(packageNameNode);
    if (resolvedElement == null || !(resolvedElement instanceof PsiDirectory)) {
        return results;
    }
    PsiDirectory resolvedPackage = (PsiDirectory) resolvedElement;
    List<IdentifierPSINode> connectors = BallerinaPsiImplUtil.getAllConnectorsFromPackage(resolvedPackage, false, false);
    results.addAll(BallerinaCompletionUtils.createConnectorLookupElements(connectors, null));
    return results;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) LookupElement(com.intellij.codeInsight.lookup.LookupElement) LinkedList(java.util.LinkedList) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with IdentifierPSINode

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

the class ConnectorReference method getVariantsInCurrentPackage.

@NotNull
private List<LookupElement> getVariantsInCurrentPackage() {
    List<LookupElement> results = new LinkedList<>();
    IdentifierPSINode identifier = getElement();
    PsiFile containingFile = identifier.getContainingFile();
    PsiFile originalFile = containingFile.getOriginalFile();
    PsiDirectory containingPackage = originalFile.getParent();
    if (containingPackage != null) {
        List<IdentifierPSINode> connectors = BallerinaPsiImplUtil.getAllConnectorsFromPackage(containingPackage, true, true);
        results.addAll(BallerinaCompletionUtils.createConnectorLookupElements(connectors, ParenthesisInsertHandler.INSTANCE));
    }
    List<LookupElement> packages = BallerinaPsiImplUtil.getPackagesAsLookups(originalFile, true, PackageCompletionInsertHandler.INSTANCE_WITH_AUTO_POPUP, true, AutoImportInsertHandler.INSTANCE_WITH_AUTO_POPUP);
    results.addAll(packages);
    return results;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiFile(com.intellij.psi.PsiFile) LookupElement(com.intellij.codeInsight.lookup.LookupElement) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with IdentifierPSINode

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

the class ConnectorReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    List<LookupElement> results = new LinkedList<>();
    IdentifierPSINode identifier = getElement();
    PsiElement parent = identifier.getParent();
    PackageNameNode packageNameNode = PsiTreeUtil.getChildOfType(parent, PackageNameNode.class);
    if (packageNameNode == null) {
        results.addAll(getVariantsInCurrentPackage());
    } else {
        results.addAll(getVariantsInPackage(packageNameNode));
    }
    return results.toArray(new LookupElement[results.size()]);
}
Also used : PackageNameNode(org.ballerinalang.plugins.idea.psi.PackageNameNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) LookupElement(com.intellij.codeInsight.lookup.LookupElement) LinkedList(java.util.LinkedList) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with IdentifierPSINode

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

the class DocVariableReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    List<LookupElement> results = new LinkedList<>();
    IdentifierPSINode identifier = getElement();
    ResourceDefinitionNode resourceDefinitionNode = PsiTreeUtil.getParentOfType(identifier, ResourceDefinitionNode.class);
    if (resourceDefinitionNode != null) {
        List<IdentifierPSINode> parameters = BallerinaPsiImplUtil.getParameters(resourceDefinitionNode);
        results.addAll(BallerinaCompletionUtils.createParameterLookupElements(parameters));
    } else {
        DocumentationAttachmentNode documentationAttachmentNode = PsiTreeUtil.getParentOfType(identifier, DocumentationAttachmentNode.class);
        if (documentationAttachmentNode == null) {
            return results.toArray(new LookupElement[results.size()]);
        }
        PsiElement nextSibling = documentationAttachmentNode.getNextSibling();
        if (nextSibling == null) {
            return results.toArray(new LookupElement[results.size()]);
        }
    }
    return results.toArray(new LookupElement[results.size()]);
}
Also used : DocumentationAttachmentNode(org.ballerinalang.plugins.idea.psi.DocumentationAttachmentNode) ResourceDefinitionNode(org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) LookupElement(com.intellij.codeInsight.lookup.LookupElement) LinkedList(java.util.LinkedList) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)109 PsiElement (com.intellij.psi.PsiElement)70 NotNull (org.jetbrains.annotations.NotNull)63 LinkedList (java.util.LinkedList)58 LookupElement (com.intellij.codeInsight.lookup.LookupElement)48 Nullable (org.jetbrains.annotations.Nullable)32 PsiDirectory (com.intellij.psi.PsiDirectory)29 PsiReference (com.intellij.psi.PsiReference)25 PsiFile (com.intellij.psi.PsiFile)24 PackageNameNode (org.ballerinalang.plugins.idea.psi.PackageNameNode)20 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)17 ScopeNode (org.antlr.jetbrains.adaptor.psi.ScopeNode)15 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)12 FieldDefinitionNode (org.ballerinalang.plugins.idea.psi.FieldDefinitionNode)12 StructDefinitionNode (org.ballerinalang.plugins.idea.psi.StructDefinitionNode)12 VariableDefinitionNode (org.ballerinalang.plugins.idea.psi.VariableDefinitionNode)10 GlobalVariableDefinitionNode (org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode)9 TypeNameNode (org.ballerinalang.plugins.idea.psi.TypeNameNode)9 ArrayList (java.util.ArrayList)8 NameReferenceNode (org.ballerinalang.plugins.idea.psi.NameReferenceNode)8