use of org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor in project kotlin by JetBrains.
the class PackagePartCodegen method generateAnnotationsForPartClass.
private void generateAnnotationsForPartClass() {
List<AnnotationDescriptor> fileAnnotationDescriptors = new ArrayList<AnnotationDescriptor>();
for (KtAnnotationEntry annotationEntry : element.getAnnotationEntries()) {
AnnotationDescriptor annotationDescriptor = state.getBindingContext().get(BindingContext.ANNOTATION, annotationEntry);
if (annotationDescriptor != null) {
fileAnnotationDescriptors.add(annotationDescriptor);
}
}
Annotated annotatedFile = new AnnotatedSimple(new AnnotationsImpl(fileAnnotationDescriptors));
AnnotationCodegen.forClass(v.getVisitor(), this, state.getTypeMapper()).genAnnotations(annotatedFile, null);
}
use of org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor in project kotlin by JetBrains.
the class AnnotationsUtils method getJsName.
@Nullable
public static String getJsName(@NotNull DeclarationDescriptor descriptor) {
AnnotationDescriptor annotation = getJsNameAnnotation(descriptor);
if (annotation == null || annotation.getAllValueArguments().isEmpty())
return null;
ConstantValue<?> value = annotation.getAllValueArguments().values().iterator().next();
if (value == null)
return null;
Object result = value.getValue();
if (!(result instanceof String))
return null;
return (String) result;
}
use of org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor in project kotlin by JetBrains.
the class AnnotationsUtils method getContainingFileAnnotations.
@NotNull
public static List<AnnotationDescriptor> getContainingFileAnnotations(@NotNull BindingContext bindingContext, @NotNull DeclarationDescriptor descriptor) {
PackageFragmentDescriptor containingPackage = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor.class, false);
if (containingPackage instanceof KotlinJavascriptPackageFragment) {
return ((KotlinJavascriptPackageFragment) containingPackage).getContainingFileAnnotations(descriptor);
}
KtFile kotlinFile = getFile(descriptor);
if (kotlinFile != null) {
List<AnnotationDescriptor> annotations = new ArrayList<AnnotationDescriptor>();
for (KtAnnotationEntry psiAnnotation : kotlinFile.getAnnotationEntries()) {
AnnotationDescriptor annotation = bindingContext.get(BindingContext.ANNOTATION, psiAnnotation);
if (annotation != null) {
annotations.add(annotation);
}
}
return annotations;
}
return Collections.emptyList();
}
use of org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor in project kotlin by JetBrains.
the class JetTestFunctionDetector method isTest.
private static boolean isTest(@NotNull FunctionDescriptor functionDescriptor) {
Annotations annotations = functionDescriptor.getAnnotations();
for (AnnotationDescriptor annotation : annotations) {
// TODO ideally we should find the fully qualified name here...
KotlinType type = annotation.getType();
String name = type.toString();
if (name.equals("Test")) {
return true;
}
}
/*
if (function.getName().startsWith("test")) {
List<JetParameter> parameters = function.getValueParameters();
return parameters.size() == 0;
}
*/
return false;
}
use of org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor in project kotlin by JetBrains.
the class ExpressionVisitor method visitAnnotatedExpression.
@Override
public JsNode visitAnnotatedExpression(@NotNull KtAnnotatedExpression expression, TranslationContext context) {
for (KtAnnotationEntry entry : expression.getAnnotationEntries()) {
AnnotationDescriptor descriptor = context.bindingContext().get(BindingContext.ANNOTATION, entry);
if (descriptor == null)
continue;
ClassifierDescriptor classifierDescriptor = descriptor.getType().getConstructor().getDeclarationDescriptor();
if (classifierDescriptor == null)
continue;
KotlinRetention retention = DescriptorUtilsKt.getAnnotationRetention(classifierDescriptor);
if (retention == KotlinRetention.SOURCE) {
KtExpression baseExpression = expression.getBaseExpression();
if (baseExpression == null)
continue;
return baseExpression.accept(this, context);
}
}
return super.visitAnnotatedExpression(expression, context);
}
Aggregations