use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method getAllAnnotationAttachmentsForType.
@NotNull
public static List<IdentifierPSINode> getAllAnnotationAttachmentsForType(@NotNull PsiDirectory packageElement, @NotNull String type, boolean includePrivate, boolean includeBuiltIns) {
List<IdentifierPSINode> results = new ArrayList<>();
// Todo - Do we need to add public to Annotations as well?
List<IdentifierPSINode> annotationDefinitions = getAllMatchingElementsFromPackage(packageElement, AnnotationDefinitionNode.class, includePrivate, includeBuiltIns);
if (annotationDefinitions.isEmpty()) {
return results;
}
for (IdentifierPSINode annotationDefinition : annotationDefinitions) {
if (annotationDefinition.getParent() instanceof AnnotationDefinitionNode) {
AnnotationDefinitionNode annotationDefinitionNode = (AnnotationDefinitionNode) annotationDefinition.getParent();
Collection<AttachmentPointNode> attachmentPointNodes = PsiTreeUtil.findChildrenOfType(annotationDefinitionNode, AttachmentPointNode.class);
if (attachmentPointNodes.isEmpty()) {
results.add(annotationDefinition);
continue;
}
for (AttachmentPointNode attachmentPointNode : attachmentPointNodes) {
// will not be available.
if (type.equals(attachmentPointNode.getText().replaceAll("<\\w*>", ""))) {
results.add(annotationDefinition);
break;
}
}
}
}
return results;
}
use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method getAllParametersInScope.
@NotNull
private static List<IdentifierPSINode> getAllParametersInScope(@NotNull ScopeNode scope, int caretOffset) {
List<IdentifierPSINode> results = new LinkedList<>();
Collection<ParameterNode> parameterNodes = PsiTreeUtil.findChildrenOfType(scope, ParameterNode.class);
for (ParameterNode parameter : parameterNodes) {
ScopeNode parentScope = PsiTreeUtil.getParentOfType(parameter, ScopeNode.class);
if (!scope.equals(parentScope)) {
continue;
}
PsiElement identifier = parameter.getNameIdentifier();
if (identifier != null && identifier instanceof IdentifierPSINode) {
results.add(((IdentifierPSINode) identifier));
}
}
Collection<CodeBlockParameterNode> codeBlockParameterNodes = PsiTreeUtil.findChildrenOfType(scope, CodeBlockParameterNode.class);
for (CodeBlockParameterNode parameter : codeBlockParameterNodes) {
PsiElement elementAtCaret = scope.getContainingFile().findElementAt(caretOffset);
if (elementAtCaret == null) {
return results;
}
if (parameter.getTextRange().getEndOffset() >= caretOffset) {
return results;
}
ScopeNode closestScope = PsiTreeUtil.getParentOfType(parameter, ScopeNode.class);
if (closestScope == null || !closestScope.equals(scope)) {
continue;
}
PsiElement identifier = parameter.getNameIdentifier();
if (identifier != null && identifier instanceof IdentifierPSINode) {
results.add(((IdentifierPSINode) identifier));
}
}
return results;
}
use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode in project ballerina by ballerina-lang.
the class BallerinaPsiImplUtil method isRedeclaredVar.
/**
* Used to identify variables used in var assignment statements are redeclared variables or not.
*
* @param identifier an identifier
* @return {@code true} if the variable is declared before in a resolvable scope, {@code false} otherwise.
*/
public static boolean isRedeclaredVar(@NotNull IdentifierPSINode identifier) {
ScopeNode scope = PsiTreeUtil.getParentOfType(identifier, CodeBlockScope.class, VariableContainer.class, TopLevelDefinition.class, LowerLevelDefinition.class);
if (scope != null) {
int caretOffset = identifier.getStartOffset();
List<IdentifierPSINode> variables = BallerinaPsiImplUtil.getAllLocalVariablesInResolvableScope(scope, caretOffset);
for (IdentifierPSINode variable : variables) {
if (variable != null && variable.getText().equals(identifier.getText())) {
return true;
}
}
List<IdentifierPSINode> parameters = BallerinaPsiImplUtil.getAllParametersInResolvableScope(scope, caretOffset);
for (IdentifierPSINode parameter : parameters) {
if (parameter != null && parameter.getText().equals(identifier.getText())) {
return true;
}
}
List<IdentifierPSINode> globalVariables = BallerinaPsiImplUtil.getAllGlobalVariablesInResolvableScope(scope);
for (IdentifierPSINode variable : globalVariables) {
if (variable != null && variable.getText().equals(identifier.getText())) {
return true;
}
}
List<IdentifierPSINode> constants = BallerinaPsiImplUtil.getAllConstantsInResolvableScope(scope);
for (IdentifierPSINode constant : constants) {
if (constant != null && constant.getText().equals(identifier.getText())) {
return true;
}
}
List<PsiElement> namespaces = BallerinaPsiImplUtil.getAllXmlNamespacesInResolvableScope(scope, caretOffset);
for (PsiElement namespace : namespaces) {
if (namespace != null && namespace.getText().equals(identifier.getText())) {
return true;
}
}
List<IdentifierPSINode> endpoints = BallerinaPsiImplUtil.getAllEndpointsInResolvableScope(scope, caretOffset);
for (IdentifierPSINode endpoint : endpoints) {
if (endpoint != null && endpoint.getText().equals(identifier.getText())) {
return true;
}
}
}
return false;
}
use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode in project ballerina by ballerina-lang.
the class AnnotationAttributeReference method resolve.
@Nullable
@Override
public PsiElement resolve() {
IdentifierPSINode identifier = getElement();
AnnotationAttachmentNode annotationAttachmentNode = PsiTreeUtil.getParentOfType(identifier, AnnotationAttachmentNode.class);
if (annotationAttachmentNode == null) {
return null;
}
AnnotationReferenceNode annotationReferenceNode = PsiTreeUtil.getChildOfType(annotationAttachmentNode, AnnotationReferenceNode.class);
if (annotationReferenceNode == null) {
return null;
}
int textLength = annotationReferenceNode.getTextLength();
PsiReference reference = annotationReferenceNode.findReferenceAt(textLength);
if (reference == null) {
return null;
}
PsiElement annotationName = reference.resolve();
if (annotationName == null || !(annotationName instanceof IdentifierPSINode)) {
return null;
}
PsiElement annotationDefinition = annotationName.getParent();
Collection<FieldDefinitionNode> fieldDefinitionNodes = PsiTreeUtil.findChildrenOfType(annotationDefinition, FieldDefinitionNode.class);
return BallerinaPsiImplUtil.resolveReference(fieldDefinitionNodes, identifier);
}
use of org.ballerinalang.plugins.idea.psi.IdentifierPSINode in project ballerina by ballerina-lang.
the class InvocationReference method getVariants.
@NotNull
@Override
public Object[] getVariants() {
StructDefinitionNode structDefinition = getStructDefinitionNode();
if (structDefinition == null) {
return new LookupElement[0];
}
List<IdentifierPSINode> attachedFunctions = BallerinaPsiImplUtil.getAttachedFunctions(structDefinition);
List<LookupElement> results = BallerinaCompletionUtils.createAttachedFunctionsLookupElements(attachedFunctions);
return results.toArray(new LookupElement[results.size()]);
}
Aggregations