Search in sources :

Example 21 with IdentifierPSINode

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

the class TransformerReference method resolve.

@Nullable
@Override
public PsiElement resolve() {
    IdentifierPSINode identifier = getElement();
    PsiFile containingFile = identifier.getContainingFile();
    if (containingFile == null) {
        return null;
    }
    PsiDirectory psiDirectory = containingFile.getParent();
    if (psiDirectory == null) {
        return null;
    }
    List<IdentifierPSINode> transformers = BallerinaPsiImplUtil.getAllTransformersFromPackage(psiDirectory, true, false);
    for (IdentifierPSINode transformer : transformers) {
        if (transformer == null) {
            continue;
        }
        if (identifier.getText().equals(transformer.getText())) {
            return transformer;
        }
    }
    return null;
}
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 22 with IdentifierPSINode

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

the class TransformerReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    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> functions = BallerinaPsiImplUtil.getAllTransformersFromPackage(containingPackage, true, true);
        results.addAll(BallerinaCompletionUtils.createTransformerLookupElements(functions));
    }
    return results.toArray(new LookupElement[results.size()]);
}
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 23 with IdentifierPSINode

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

the class TypeReference method resolve.

@Nullable
public static PsiElement resolve(PsiElement typeNameNode, IdentifierPSINode identifier) {
    String valueTypeName = typeNameNode.getText();
    Project project = typeNameNode.getProject();
    PsiFile psiFile = BallerinaPsiImplUtil.findPsiFileInSDK(project, typeNameNode, "/ballerina/builtin/" + valueTypeName + "lib.bal");
    if (psiFile == null) {
        return null;
    }
    List<IdentifierPSINode> functionDefinitions = BallerinaPsiImplUtil.getMatchingElementsFromAFile(psiFile, FunctionDefinitionNode.class, false);
    for (IdentifierPSINode functionDefinition : functionDefinitions) {
        if (functionDefinition != null && identifier.getText().equals(functionDefinition.getText())) {
            return functionDefinition;
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with IdentifierPSINode

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

the class AnnotationReference 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();
    } else {
        return resolveInPackage(packageNameNode);
    }
}
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 25 with IdentifierPSINode

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

the class AnnotationReference method getVariantsFromCurrentPackage.

@NotNull
private List<LookupElement> getVariantsFromCurrentPackage(boolean allAnnotations) {
    List<LookupElement> results = new LinkedList<>();
    IdentifierPSINode identifier = getElement();
    PsiElement parent = identifier.getParent();
    PsiFile containingFile = parent.getContainingFile();
    PsiFile originalFile = containingFile.getOriginalFile();
    List<LookupElement> packages = BallerinaPsiImplUtil.getPackagesAsLookups(originalFile, true, PackageCompletionInsertHandler.INSTANCE_WITH_AUTO_POPUP, true, AutoImportInsertHandler.INSTANCE_WITH_AUTO_POPUP);
    results.addAll(packages);
    PsiDirectory containingPackage = originalFile.getParent();
    if (containingPackage == null) {
        return results;
    }
    List<IdentifierPSINode> annotations;
    if (allAnnotations) {
        annotations = BallerinaPsiImplUtil.getAllAnnotationsInPackage(containingPackage, true, true);
    } else {
        String attachmentType = BallerinaPsiImplUtil.getAttachmentType(identifier);
        if (attachmentType == null) {
            return results;
        }
        annotations = BallerinaPsiImplUtil.getAllAnnotationAttachmentsForType(containingPackage, attachmentType, true, true);
    }
    results.addAll(BallerinaCompletionUtils.createAnnotationLookupElements(annotations));
    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) 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