Search in sources :

Example 1 with AnnotationReference

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

the class BallerinaCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    // The file will be loaded to memory and and will be edited. parameters.getOriginalFile()
    // contains the original file. parameters.getPosition().getContainingFile() will return null
    // because it only exists in the memory. So use parameters.getOriginalFile().getContainingFile()
    // if you want to get the details like containing directory, etc.
    PsiElement element = parameters.getPosition();
    PsiElement parent = element.getParent();
    if (parent instanceof PackageNameNode) {
        handlePackageNameNode(parameters, result);
    } else if (parent instanceof ImportDeclarationNode) {
        handleImportDeclarationNode(parameters, result);
    }
    // Otherwise we only suggest attachable annotations only.
    if (parameters.isExtendedCompletion()) {
        PsiReference reference = element.findReferenceAt(0);
        if (reference instanceof AnnotationReference) {
            List<LookupElement> variants = ((AnnotationReference) reference).getVariants(true);
            result.addAllElements(variants);
            result.addLookupAdvertisement("Showing all annotations in the package");
        }
    }
}
Also used : PackageNameNode(org.ballerinalang.plugins.idea.psi.PackageNameNode) ImportDeclarationNode(org.ballerinalang.plugins.idea.psi.ImportDeclarationNode) PsiReference(com.intellij.psi.PsiReference) AnnotationReference(org.ballerinalang.plugins.idea.psi.references.AnnotationReference) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1 ImportDeclarationNode (org.ballerinalang.plugins.idea.psi.ImportDeclarationNode)1 PackageNameNode (org.ballerinalang.plugins.idea.psi.PackageNameNode)1 AnnotationReference (org.ballerinalang.plugins.idea.psi.references.AnnotationReference)1