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()]);
}
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;
}
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()]);
}
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;
}
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;
}
Aggregations