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