Search in sources :

Example 36 with IdentifierPSINode

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

the class WorkerReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    List<LookupElement> results = new LinkedList<>();
    IdentifierPSINode identifier = getElement();
    ScopeNode scopeNode = PsiTreeUtil.getParentOfType(identifier, ScopeNode.class);
    if (scopeNode == null) {
        return results.toArray(new LookupElement[results.size()]);
    }
    if (scopeNode instanceof JoinClauseNode) {
        scopeNode = (ScopeNode) scopeNode.getParent();
    }
    List<WorkerDeclarationNode> workerDeclarations = BallerinaPsiImplUtil.getWorkerDeclarationsInScope(scopeNode);
    results.addAll(BallerinaCompletionUtils.createWorkerLookupElements(workerDeclarations));
    return results.toArray(new LookupElement[results.size()]);
}
Also used : WorkerDeclarationNode(org.ballerinalang.plugins.idea.psi.WorkerDeclarationNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) JoinClauseNode(org.ballerinalang.plugins.idea.psi.JoinClauseNode) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ScopeNode(org.antlr.jetbrains.adaptor.psi.ScopeNode) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with IdentifierPSINode

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

the class BallerinaUnresolvedReferenceInspection method getUnresolvedNameReferenceDescriptors.

private List<ProblemDescriptor> getUnresolvedNameReferenceDescriptors(@NotNull InspectionManager manager, boolean isOnTheFly, @NotNull LocalQuickFix[] availableFixes, @NotNull Collection<NameReferenceNode> nodes) {
    List<ProblemDescriptor> problemDescriptors = new LinkedList<>();
    for (NameReferenceNode node : nodes) {
        ProgressManager.checkCanceled();
        if (node == null || "_".equals(node.getText())) {
            continue;
        }
        PackageNameNode packageNameNode = PsiTreeUtil.getChildOfType(node, PackageNameNode.class);
        if (packageNameNode != null) {
            PsiReference reference = packageNameNode.findReferenceAt(0);
            if (reference != null) {
                PsiElement resolvedElement = reference.resolve();
                if (resolvedElement != null && resolvedElement.getParent() instanceof NamespaceDeclarationNode) {
                    continue;
                }
            }
        }
        IdentifierPSINode identifier = PsiTreeUtil.getChildOfType(node, IdentifierPSINode.class);
        if (identifier == null) {
            continue;
        }
        AssignmentStatementNode assignmentStatementNode = PsiTreeUtil.getParentOfType(identifier, AssignmentStatementNode.class);
        if (assignmentStatementNode == null) {
            continue;
        }
        boolean isValidVarVariable = BallerinaPsiImplUtil.isValidVarVariable(assignmentStatementNode, identifier);
        if (isValidVarVariable) {
            continue;
        }
        PsiReference reference = identifier.getReference();
        if (reference == null || reference.resolve() == null) {
            problemDescriptors.add(createProblemDescriptor(manager, identifier, isOnTheFly, availableFixes));
        }
    }
    return problemDescriptors;
}
Also used : PackageNameNode(org.ballerinalang.plugins.idea.psi.PackageNameNode) AssignmentStatementNode(org.ballerinalang.plugins.idea.psi.AssignmentStatementNode) NamespaceDeclarationNode(org.ballerinalang.plugins.idea.psi.NamespaceDeclarationNode) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiReference(com.intellij.psi.PsiReference) LinkedList(java.util.LinkedList) NameReferenceNode(org.ballerinalang.plugins.idea.psi.NameReferenceNode) PsiElement(com.intellij.psi.PsiElement)

Example 38 with IdentifierPSINode

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

the class UnusedVariableInspection method checkFile.

@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    List<ProblemDescriptor> problemDescriptors = new LinkedList<>();
    List<LocalQuickFix> availableFixes = new ArrayList<>();
    Collection<VariableDefinitionNode> variables = PsiTreeUtil.findChildrenOfType(file, VariableDefinitionNode.class);
    for (VariableDefinitionNode variable : variables) {
        ProgressManager.checkCanceled();
        PsiElement identifier = variable.getNameIdentifier();
        if (identifier == null) {
            continue;
        }
        Query<PsiReference> psiReferences = ReferencesSearch.search(identifier);
        PsiReference firstReference = psiReferences.findFirst();
        if (firstReference == null) {
            ProblemDescriptor problemDescriptor = getProblemDescriptor(manager, isOnTheFly, identifier, availableFixes);
            problemDescriptors.add(problemDescriptor);
        }
    }
    Collection<AssignmentStatementNode> assignmentStatementNodes = PsiTreeUtil.findChildrenOfType(file, AssignmentStatementNode.class);
    for (AssignmentStatementNode assignmentStatementNode : assignmentStatementNodes) {
        ProgressManager.checkCanceled();
        boolean isVarAssignment = BallerinaPsiImplUtil.isVarAssignmentStatement(assignmentStatementNode);
        if (isVarAssignment) {
            List<IdentifierPSINode> identifiers = BallerinaPsiImplUtil.getVariablesFromVarAssignment(assignmentStatementNode);
            for (IdentifierPSINode identifier : identifiers) {
                if (BallerinaPsiImplUtil.isRedeclaredVar(identifier)) {
                    continue;
                }
                Query<PsiReference> psiReferences = ReferencesSearch.search(identifier);
                PsiReference firstReference = psiReferences.findFirst();
                if (firstReference == null && !"_".equals(identifier.getText())) {
                    ProblemDescriptor problemDescriptor = getProblemDescriptor(manager, isOnTheFly, identifier, availableFixes);
                    problemDescriptors.add(problemDescriptor);
                }
            }
        }
    }
    return problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]);
}
Also used : AssignmentStatementNode(org.ballerinalang.plugins.idea.psi.AssignmentStatementNode) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) ArrayList(java.util.ArrayList) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiReference(com.intellij.psi.PsiReference) LinkedList(java.util.LinkedList) VariableDefinitionNode(org.ballerinalang.plugins.idea.psi.VariableDefinitionNode) IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with IdentifierPSINode

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

the class BallerinaCompletionUtils method createAnnotationLookupElements.

@NotNull
public static List<LookupElement> createAnnotationLookupElements(@NotNull List<IdentifierPSINode> annotations) {
    List<LookupElement> lookupElements = new LinkedList<>();
    for (IdentifierPSINode annotation : annotations) {
        if (annotation == null) {
            continue;
        }
        LookupElement lookupElement = BallerinaCompletionUtils.createAnnotationLookupElement(annotation);
        lookupElements.add(lookupElement);
    }
    return lookupElements;
}
Also used : IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PrioritizedLookupElement(com.intellij.codeInsight.completion.PrioritizedLookupElement) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with IdentifierPSINode

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

the class BallerinaCompletionUtils method createVariableLookupElements.

@NotNull
public static List<LookupElement> createVariableLookupElements(@NotNull List<IdentifierPSINode> variables) {
    List<LookupElement> lookupElements = new LinkedList<>();
    for (IdentifierPSINode variable : variables) {
        if (variable == null) {
            continue;
        }
        LookupElement lookupElement = BallerinaCompletionUtils.createVariableLookupElement(variable);
        lookupElements.add(lookupElement);
    }
    return lookupElements;
}
Also used : IdentifierPSINode(org.ballerinalang.plugins.idea.psi.IdentifierPSINode) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PrioritizedLookupElement(com.intellij.codeInsight.completion.PrioritizedLookupElement) 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