From 51ecfe2a093079c98005f669703672dea5d0b2bc Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 9 Jul 2014 22:19:35 +0400 Subject: [PATCH] Don't fail on a bad Retention annotation in light classes #KT-5450 Fixed No new tests added because it seems there are no tests on highlighting which cause light class generation, where the original error occurred --- .../jet/codegen/AnnotationCodegen.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java index aedc5477e98..06bdae20404 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AnnotationCodegen.java @@ -350,18 +350,23 @@ public abstract class AnnotationCodegen { @NotNull private RetentionPolicy getRetentionPolicy(@NotNull Annotated descriptor) { AnnotationDescriptor retentionAnnotation = descriptor.getAnnotations().findAnnotation(new FqName(Retention.class.getName())); - if (retentionAnnotation == null) return RetentionPolicy.CLASS; + if (retentionAnnotation != null) { + Collection> valueArguments = retentionAnnotation.getAllValueArguments().values(); + if (!valueArguments.isEmpty()) { + CompileTimeConstant compileTimeConstant = valueArguments.iterator().next(); + if (compileTimeConstant instanceof EnumValue) { + ClassDescriptor enumEntry = ((EnumValue) compileTimeConstant).getValue(); + JetType classObjectType = enumEntry.getClassObjectType(); + if (classObjectType != null) { + if ("java/lang/annotation/RetentionPolicy".equals(typeMapper.mapType(classObjectType).getInternalName())) { + return RetentionPolicy.valueOf(enumEntry.getName().asString()); + } + } + } + } + } - Collection> valueArguments = retentionAnnotation.getAllValueArguments().values(); - assert valueArguments.size() == 1 : "Retention should have an argument: " + retentionAnnotation + " on " + descriptor; - CompileTimeConstant compileTimeConstant = valueArguments.iterator().next(); - assert compileTimeConstant instanceof EnumValue : "Retention argument should be enum value: " + compileTimeConstant; - ClassDescriptor enumEntry = ((EnumValue) compileTimeConstant).getValue(); - JetType classObjectType = enumEntry.getClassObjectType(); - assert classObjectType != null : "Enum entry should have a class object: " + enumEntry; - assert "java/lang/annotation/RetentionPolicy".equals(typeMapper.mapType(classObjectType).getInternalName()) : - "Retention argument should be of type RetentionPolicy: " + enumEntry; - return RetentionPolicy.valueOf(enumEntry.getName().asString()); + return RetentionPolicy.CLASS; } @NotNull