Search in sources :

Example 96 with IdentifierPSINode

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

the class AnnotationReference method getVariantsFromPackage.

@NotNull
private List<LookupElement> getVariantsFromPackage(@NotNull PackageNameNode packageNameNode, boolean allAnnotations) {
    List<LookupElement> results = new LinkedList<>();
    IdentifierPSINode identifier = getElement();
    PsiElement resolvedElement = BallerinaPsiImplUtil.resolvePackage(packageNameNode);
    if (resolvedElement == null || !(resolvedElement instanceof PsiDirectory)) {
        return results;
    }
    PsiDirectory resolvedPackage = (PsiDirectory) resolvedElement;
    List<IdentifierPSINode> annotations;
    if (allAnnotations) {
        annotations = BallerinaPsiImplUtil.getAllAnnotationsInPackage(resolvedPackage, false, true);
    } else {
        String attachmentType = BallerinaPsiImplUtil.getAttachmentType(identifier);
        if (attachmentType == null) {
            return results;
        }
        annotations = BallerinaPsiImplUtil.getAllAnnotationAttachmentsForType(resolvedPackage, attachmentType, false, true);
    }
    results.addAll(BallerinaCompletionUtils.createAnnotationLookupElements(annotations));
    return results;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) 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 97 with IdentifierPSINode

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

the class AnnotationReference method findMatchingAnnotationDefinition.

@Nullable
private PsiElement findMatchingAnnotationDefinition(@NotNull PsiDirectory currentPackage, boolean includePrivate) {
    IdentifierPSINode identifier = getElement();
    List<IdentifierPSINode> annotations = BallerinaPsiImplUtil.getAllAnnotationsInPackage(currentPackage, includePrivate, true);
    for (IdentifierPSINode annotation : annotations) {
        if (annotation == null) {
            continue;
        }
        String text = annotation.getText();
        if (text.equals(identifier.getText())) {
            return annotation;
        }
    }
    return null;
}
Also used : IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) Nullable(org.jetbrains.annotations.Nullable)

Example 98 with IdentifierPSINode

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

the class AnnotationReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    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(false));
    } else {
        results.addAll(getVariantsFromPackage(packageNameNode, false));
    }
    return results.toArray(new LookupElement[results.size()]);
}
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 99 with IdentifierPSINode

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

the class EnumFieldReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    List<LookupElement> results = new LinkedList<>();
    IdentifierPSINode identifier = getElement();
    PsiElement dot = PsiTreeUtil.prevVisibleLeaf(identifier);
    if (dot == null || !".".equals(dot.getText())) {
        return results.toArray(new LookupElement[results.size()]);
    }
    PsiElement enumReferenceNode = PsiTreeUtil.prevVisibleLeaf(dot);
    if (enumReferenceNode == null) {
        return results.toArray(new LookupElement[results.size()]);
    }
    PsiReference reference = enumReferenceNode.findReferenceAt(enumReferenceNode.getTextLength());
    if (reference == null) {
        return results.toArray(new LookupElement[results.size()]);
    }
    PsiElement resolvedElement = reference.resolve();
    if (resolvedElement == null) {
        return results.toArray(new LookupElement[results.size()]);
    }
    PsiElement resolvedElementParent = resolvedElement.getParent();
    if (!(resolvedElementParent instanceof EnumDefinitionNode)) {
        return results.toArray(new LookupElement[results.size()]);
    }
    Collection<EnumFieldNode> fieldDefinitionNodes = PsiTreeUtil.findChildrenOfType(resolvedElementParent, EnumFieldNode.class);
    results.addAll(BallerinaCompletionUtils.createEnumFieldLookupElements(fieldDefinitionNodes, (IdentifierPSINode) resolvedElement));
    return results.toArray(new LookupElement[results.size()]);
}
Also used : EnumFieldNode(org.ballerinalang.plugins.idea.psi.EnumFieldNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiReference(com.intellij.psi.PsiReference) LookupElement(com.intellij.codeInsight.lookup.LookupElement) EnumDefinitionNode(org.ballerinalang.plugins.idea.psi.EnumDefinitionNode) LinkedList(java.util.LinkedList) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 100 with IdentifierPSINode

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

the class EnumReference method getVariantsFromCurrentPackage.

@NotNull
private List<LookupElement> getVariantsFromCurrentPackage() {
    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> enums = BallerinaPsiImplUtil.getAllEnumsFromPackage(containingPackage, true, true);
        results.addAll(BallerinaCompletionUtils.createEnumLookupElements(enums, null));
    }
    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) 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