Search in sources :

Example 11 with AnnotationAttachmentNode

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

the class AnnotationAttributeReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    IdentifierPSINode identifier = getElement();
    AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getParentOfType(identifier, AnnotationAttachmentNode.class);
    if (annotationAttachmentNode == null) {
        return new Object[0];
    }
    AnnotationReferenceNode annotationReferenceNode = PsiTreeUtil.getChildOfType(annotationAttachmentNode, AnnotationReferenceNode.class);
    if (annotationReferenceNode == null) {
        return new Object[0];
    }
    int textLength = annotationReferenceNode.getTextLength();
    PsiReference reference = annotationReferenceNode.findReferenceAt(textLength);
    if (reference == null) {
        return new Object[0];
    }
    PsiElement annotationName = reference.resolve();
    if (annotationName == null || !(annotationName instanceof IdentifierPSINode)) {
        return new Object[0];
    }
    PsiElement annotationDefinition = annotationName.getParent();
    Collection<FieldDefinitionNode> fieldDefinitionNodes = PsiTreeUtil.findChildrenOfType(annotationDefinition, FieldDefinitionNode.class);
    List<LookupElement> results = BallerinaCompletionUtils.createFieldLookupElements(fieldDefinitionNodes, (IdentifierPSINode) annotationName, PackageCompletionInsertHandler.INSTANCE_WITH_AUTO_POPUP);
    return results.toArray(new LookupElement[results.size()]);
}
Also used : IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiReference(com.intellij.psi.PsiReference) FieldDefinitionNode(org.ballerinalang.plugins.idea.psi.FieldDefinitionNode) LookupElement(com.intellij.codeInsight.lookup.LookupElement) AnnotationReferenceNode(org.ballerinalang.plugins.idea.psi.AnnotationReferenceNode) PsiElement(com.intellij.psi.PsiElement) AnnotationAttachmentNode(org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AnnotationAttachmentNode (org.ballerinalang.plugins.idea.psi.AnnotationAttachmentNode)11 PsiElement (com.intellij.psi.PsiElement)9 IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)7 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)5 ConstantDefinitionNode (org.ballerinalang.plugins.idea.psi.ConstantDefinitionNode)5 FieldDefinitionNode (org.ballerinalang.plugins.idea.psi.FieldDefinitionNode)5 GlobalVariableDefinitionNode (org.ballerinalang.plugins.idea.psi.GlobalVariableDefinitionNode)5 ResourceDefinitionNode (org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode)5 PsiReference (com.intellij.psi.PsiReference)4 AnnotationReferenceNode (org.ballerinalang.plugins.idea.psi.AnnotationReferenceNode)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 IElementType (com.intellij.psi.tree.IElementType)3 ANTLRPsiNode (org.antlr.jetbrains.adaptor.psi.ANTLRPsiNode)3 ParameterNode (org.ballerinalang.plugins.idea.psi.ParameterNode)3 ServiceBodyNode (org.ballerinalang.plugins.idea.psi.ServiceBodyNode)3 StructDefinitionNode (org.ballerinalang.plugins.idea.psi.StructDefinitionNode)3 TypeNameNode (org.ballerinalang.plugins.idea.psi.TypeNameNode)3 NotNull (org.jetbrains.annotations.NotNull)3 Annotation (com.intellij.lang.annotation.Annotation)2 PsiDirectory (com.intellij.psi.PsiDirectory)2