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:
Alexander Udalov
2014-07-09 22:19:35 +04:00
parent 0e758b97f7
commit 51ecfe2a09
@@ -350,19 +350,24 @@ 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(); Collection<CompileTimeConstant<?>> valueArguments = retentionAnnotation.getAllValueArguments().values();
assert valueArguments.size() == 1 : "Retention should have an argument: " + retentionAnnotation + " on " + descriptor; if (!valueArguments.isEmpty()) {
CompileTimeConstant<?> compileTimeConstant = valueArguments.iterator().next(); CompileTimeConstant<?> compileTimeConstant = valueArguments.iterator().next();
assert compileTimeConstant instanceof EnumValue : "Retention argument should be enum value: " + compileTimeConstant; if (compileTimeConstant instanceof EnumValue) {
ClassDescriptor enumEntry = ((EnumValue) compileTimeConstant).getValue(); ClassDescriptor enumEntry = ((EnumValue) compileTimeConstant).getValue();
JetType classObjectType = enumEntry.getClassObjectType(); JetType classObjectType = enumEntry.getClassObjectType();
assert classObjectType != null : "Enum entry should have a class object: " + enumEntry; if (classObjectType != null) {
assert "java/lang/annotation/RetentionPolicy".equals(typeMapper.mapType(classObjectType).getInternalName()) : if ("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.valueOf(enumEntry.getName().asString());
} }
}
}
}
}
return RetentionPolicy.CLASS;
}
@NotNull @NotNull
abstract AnnotationVisitor visitAnnotation(String descr, boolean visible); abstract AnnotationVisitor visitAnnotation(String descr, boolean visible);