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
This commit is contained in:
@@ -350,18 +350,23 @@ public abstract class AnnotationCodegen {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private RetentionPolicy getRetentionPolicy(@NotNull Annotated descriptor) {
|
private RetentionPolicy getRetentionPolicy(@NotNull Annotated descriptor) {
|
||||||
AnnotationDescriptor retentionAnnotation = descriptor.getAnnotations().findAnnotation(new FqName(Retention.class.getName()));
|
AnnotationDescriptor retentionAnnotation = descriptor.getAnnotations().findAnnotation(new FqName(Retention.class.getName()));
|
||||||
if (retentionAnnotation == null) return RetentionPolicy.CLASS;
|
if (retentionAnnotation != null) {
|
||||||
|
Collection<CompileTimeConstant<?>> 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<CompileTimeConstant<?>> valueArguments = retentionAnnotation.getAllValueArguments().values();
|
return RetentionPolicy.CLASS;
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user