Load java: load annotations on enum entries
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package test;
|
||||
|
||||
import java.lang.String;
|
||||
import java.util.List;
|
||||
|
||||
public enum AnnotatedEnumEntry {
|
||||
@Anno("a")
|
||||
E1,
|
||||
@Anno("b")
|
||||
@Anno2
|
||||
E2,
|
||||
E3;
|
||||
|
||||
public static @interface Anno {
|
||||
String value();
|
||||
}
|
||||
|
||||
public static @interface Anno2 {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package test
|
||||
|
||||
public final enum class AnnotatedEnumEntry : kotlin.Enum<test.AnnotatedEnumEntry!> {
|
||||
@test.AnnotatedEnumEntry.Anno(value = "a") enum entry E1
|
||||
|
||||
@test.AnnotatedEnumEntry.Anno(value = "b") @test.AnnotatedEnumEntry.Anno2() enum entry E2
|
||||
|
||||
enum entry E3
|
||||
|
||||
private constructor AnnotatedEnumEntry()
|
||||
public final override /*1*/ /*fake_override*/ val name: kotlin.String
|
||||
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
|
||||
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
|
||||
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: test.AnnotatedEnumEntry!): kotlin.Int
|
||||
|
||||
public final annotation class Anno : kotlin.Annotation {
|
||||
public constructor Anno(/*0*/ value: kotlin.String)
|
||||
public final val value: kotlin.String
|
||||
}
|
||||
|
||||
public final annotation class Anno2 : kotlin.Annotation {
|
||||
public constructor Anno2()
|
||||
}
|
||||
|
||||
// Static members
|
||||
@kotlin.Deprecated(message = "Use 'values()' function instead", replaceWith = kotlin.ReplaceWith(expression = "this.values()", imports = {})) public final /*synthesized*/ val values: kotlin.Array<test.AnnotatedEnumEntry>
|
||||
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): test.AnnotatedEnumEntry
|
||||
public final /*synthesized*/ fun values(): kotlin.Array<test.AnnotatedEnumEntry>
|
||||
}
|
||||
@@ -321,6 +321,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
doTestCompiledJava(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotatedEnumEntry.java")
|
||||
public void testAnnotatedEnumEntry() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledJava/annotations/AnnotatedEnumEntry.java");
|
||||
doTestCompiledJava(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotatedField.java")
|
||||
public void testAnnotatedField() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledJava/annotations/AnnotatedField.java");
|
||||
|
||||
+6
@@ -3387,6 +3387,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotatedEnumEntry.java")
|
||||
public void testAnnotatedEnumEntry() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledJava/annotations/AnnotatedEnumEntry.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotatedField.java")
|
||||
public void testAnnotatedField() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledJava/annotations/AnnotatedField.java");
|
||||
|
||||
+2
-2
@@ -585,8 +585,8 @@ public class LazyJavaClassMemberScope(
|
||||
if (field != null) {
|
||||
EnumEntrySyntheticClassDescriptor.create(c.storageManager, ownerDescriptor, name,
|
||||
c.storageManager.createLazyValue {
|
||||
memberIndex().getAllFieldNames() + memberIndex().getMethodNames({true})
|
||||
}, c.components.sourceElementFactory.source(field))
|
||||
memberIndex().getAllFieldNames() + memberIndex().getMethodNames({ true })
|
||||
}, c.resolveAnnotations(field), c.components.sourceElementFactory.source(field))
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
+6
-3
@@ -47,6 +47,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
private final MemberScope scope;
|
||||
private final MemberScope staticScope = new StaticScopeForKotlinClass(this);
|
||||
private final NotNullLazyValue<Collection<Name>> enumMemberNames;
|
||||
private final Annotations annotations;
|
||||
|
||||
/**
|
||||
* Creates and initializes descriptors for enum entry with the given name and its companion object
|
||||
@@ -58,11 +59,12 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
@NotNull ClassDescriptor enumClass,
|
||||
@NotNull Name name,
|
||||
@NotNull NotNullLazyValue<Collection<Name>> enumMemberNames,
|
||||
@NotNull Annotations annotations,
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
KotlinType enumType = enumClass.getDefaultType();
|
||||
|
||||
return new EnumEntrySyntheticClassDescriptor(storageManager, enumClass, enumType, name, enumMemberNames, source);
|
||||
return new EnumEntrySyntheticClassDescriptor(storageManager, enumClass, enumType, name, enumMemberNames, annotations, source);
|
||||
}
|
||||
|
||||
private EnumEntrySyntheticClassDescriptor(
|
||||
@@ -71,11 +73,13 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
@NotNull KotlinType supertype,
|
||||
@NotNull Name name,
|
||||
@NotNull NotNullLazyValue<Collection<Name>> enumMemberNames,
|
||||
@NotNull Annotations annotations,
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
super(storageManager, containingClass, name, source);
|
||||
assert containingClass.getKind() == ClassKind.ENUM_CLASS;
|
||||
|
||||
this.annotations = annotations;
|
||||
this.typeConstructor =
|
||||
TypeConstructorImpl.createForClass(this, getAnnotations(), true, "enum entry", Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.singleton(supertype));
|
||||
@@ -160,8 +164,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations getAnnotations() {
|
||||
// TODO
|
||||
return Annotations.Companion.getEMPTY();
|
||||
return annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -304,7 +304,8 @@ public class DeserializedClassDescriptor(
|
||||
name ->
|
||||
if (name in enumEntryNames) {
|
||||
EnumEntrySyntheticClassDescriptor.create(
|
||||
c.storageManager, this@DeserializedClassDescriptor, name, enumMemberNames, SourceElement.NO_SOURCE
|
||||
//TODO: load annotations from class file
|
||||
c.storageManager, this@DeserializedClassDescriptor, name, enumMemberNames, Annotations.EMPTY, SourceElement.NO_SOURCE
|
||||
)
|
||||
}
|
||||
else null
|
||||
|
||||
Reference in New Issue
Block a user