Search in sources :

Example 91 with IdentifierPSINode

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

the class StructReference method resolveInPackage.

@Nullable
private PsiElement resolveInPackage(PackageNameNode packageNameNode) {
    PsiElement resolvedElement = BallerinaPsiImplUtil.resolvePackage(packageNameNode);
    if (resolvedElement == null || !(resolvedElement instanceof PsiDirectory)) {
        return null;
    }
    PsiDirectory psiDirectory = (PsiDirectory) resolvedElement;
    IdentifierPSINode identifier = getElement();
    return BallerinaPsiImplUtil.resolveElementInPackage(psiDirectory, identifier, false, false, true, false, false, false, false, false);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 92 with IdentifierPSINode

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

the class StructReference method resolveInCurrentPackage.

@Nullable
private PsiElement resolveInCurrentPackage() {
    IdentifierPSINode identifier = getElement();
    PsiFile containingFile = identifier.getContainingFile();
    if (containingFile == null) {
        return null;
    }
    PsiFile originalFile = containingFile.getOriginalFile();
    PsiDirectory psiDirectory = originalFile.getParent();
    if (psiDirectory == null) {
        return null;
    }
    return BallerinaPsiImplUtil.resolveElementInPackage(psiDirectory, identifier, false, false, true, false, false, false, true, true);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 93 with IdentifierPSINode

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

the class TypeReference method getVariants.

@NotNull
public static Object[] getVariants(PsiElement typeNameNode) {
    String valueTypeName = typeNameNode.getText();
    Project project = typeNameNode.getProject();
    PsiFile psiFile = BallerinaPsiImplUtil.findPsiFileInSDK(project, typeNameNode, "/ballerina/builtin/" + valueTypeName + "lib.bal");
    if (psiFile == null) {
        return new LookupElement[0];
    }
    List<LookupElement> results = new LinkedList<>();
    List<IdentifierPSINode> functionDefinitions = BallerinaPsiImplUtil.getMatchingElementsFromAFile(psiFile, FunctionDefinitionNode.class, false);
    results.addAll(BallerinaCompletionUtils.createFunctionLookupElements(functionDefinitions));
    return results.toArray(new LookupElement[results.size()]);
}
Also used : Project(com.intellij.openapi.project.Project) 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 94 with IdentifierPSINode

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

the class AnnotationReference method getVariants.

@NotNull
public List<LookupElement> getVariants(boolean allAnnotations) {
    List<LookupElement> results = new LinkedList<>();
    IdentifierPSINode identifier = getElement();
    PsiElement parent = identifier.getParent();
    PackageNameNode packageNameNode = PsiTreeUtil.getChildOfType(parent, PackageNameNode.class);
    if (packageNameNode == null) {
        results.addAll(getVariantsFromCurrentPackage(allAnnotations));
    } else {
        results.addAll(getVariantsFromPackage(packageNameNode, allAnnotations));
    }
    return results;
}
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 95 with IdentifierPSINode

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

the class AnnotationReference method resolveInCurrentPackage.

@Nullable
private PsiElement resolveInCurrentPackage() {
    IdentifierPSINode identifier = getElement();
    PsiElement parent = identifier.getParent();
    PsiFile containingFile = parent.getContainingFile();
    PsiFile originalFile = containingFile.getOriginalFile();
    PsiDirectory currentPackage = originalFile.getParent();
    if (currentPackage == null) {
        return null;
    }
    return findMatchingAnnotationDefinition(currentPackage, true);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

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