Search in sources :

Example 1 with SourceNotationNode

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

the class PackageNameReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    IdentifierPSINode identifier = getElement();
    FullyQualifiedPackageNameNode fullyQualifiedPackageNameNode = PsiTreeUtil.getParentOfType(identifier, FullyQualifiedPackageNameNode.class);
    if (fullyQualifiedPackageNameNode != null) {
        return new LookupElement[0];
    }
    List<LookupElement> results = new ArrayList<>();
    PsiFile containingFile = identifier.getContainingFile();
    PsiFile originalFile = containingFile.getOriginalFile();
    // We don't need to add ':' at the end of the package name in SourceNotationNode.
    InsertHandler<LookupElement> importedPackagesInsertHandler = PackageCompletionInsertHandler.INSTANCE_WITH_AUTO_POPUP;
    InsertHandler<LookupElement> unImportedPackagesInsertHandler = AutoImportInsertHandler.INSTANCE_WITH_AUTO_POPUP;
    SourceNotationNode sourceNotationNode = PsiTreeUtil.getParentOfType(identifier, SourceNotationNode.class);
    if (sourceNotationNode != null) {
        importedPackagesInsertHandler = null;
        unImportedPackagesInsertHandler = AutoImportInsertHandler.INSTANCE;
    }
    List<LookupElement> packages = BallerinaPsiImplUtil.getPackagesAsLookups(originalFile, true, importedPackagesInsertHandler, true, unImportedPackagesInsertHandler);
    results.addAll(packages);
    return results.toArray(new LookupElement[results.size()]);
}
Also used : FullyQualifiedPackageNameNode(org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode) SourceNotationNode(org.ballerinalang.plugins.idea.psi.SourceNotationNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 PsiFile (com.intellij.psi.PsiFile)1 ArrayList (java.util.ArrayList)1 FullyQualifiedPackageNameNode (org.ballerinalang.plugins.idea.psi.FullyQualifiedPackageNameNode)1 IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)1 SourceNotationNode (org.ballerinalang.plugins.idea.psi.SourceNotationNode)1 NotNull (org.jetbrains.annotations.NotNull)1