Search in sources :

Example 1 with AnnotationDescriptor

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);
}
Also used : AnnotationDescriptor(org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor) Annotated(org.jetbrains.kotlin.descriptors.annotations.Annotated) ArrayList(java.util.ArrayList) AnnotatedSimple(org.jetbrains.kotlin.codegen.annotation.AnnotatedSimple) AnnotationsImpl(org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl)

Example 2 with AnnotationDescriptor

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;
}
Also used : AnnotationDescriptor(org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with AnnotationDescriptor

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();
}
Also used : AnnotationDescriptor(org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor) KtAnnotationEntry(org.jetbrains.kotlin.psi.KtAnnotationEntry) KotlinJavascriptPackageFragment(org.jetbrains.kotlin.serialization.js.KotlinJavascriptPackageFragment) ArrayList(java.util.ArrayList) KtFile(org.jetbrains.kotlin.psi.KtFile) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with AnnotationDescriptor

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;
}
Also used : AnnotationDescriptor(org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor) Annotations(org.jetbrains.kotlin.descriptors.annotations.Annotations) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 5 with AnnotationDescriptor

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);
}
Also used : AnnotationDescriptor(org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor) KotlinRetention(org.jetbrains.kotlin.descriptors.annotations.KotlinRetention)

Aggregations

AnnotationDescriptor (org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor)9 Nullable (org.jetbrains.annotations.Nullable)3 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 FqNameUnsafe (org.jetbrains.kotlin.name.FqNameUnsafe)2 AnnotatedSimple (org.jetbrains.kotlin.codegen.annotation.AnnotatedSimple)1 Annotated (org.jetbrains.kotlin.descriptors.annotations.Annotated)1 Annotations (org.jetbrains.kotlin.descriptors.annotations.Annotations)1 AnnotationsImpl (org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl)1 KotlinRetention (org.jetbrains.kotlin.descriptors.annotations.KotlinRetention)1 JavaClassDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)1 FqName (org.jetbrains.kotlin.name.FqName)1 KtAnnotationEntry (org.jetbrains.kotlin.psi.KtAnnotationEntry)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1 ArrayValue (org.jetbrains.kotlin.resolve.constants.ArrayValue)1 ConstantValue (org.jetbrains.kotlin.resolve.constants.ConstantValue)1 KClassValue (org.jetbrains.kotlin.resolve.constants.KClassValue)1 KotlinJavascriptPackageFragment (org.jetbrains.kotlin.serialization.js.KotlinJavascriptPackageFragment)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1