Add info about Java 14 record to IR. Add support to Metaprogramming API

This commit is contained in:
Ivan Hetman 2023-02-11 22:05:07 +02:00 committed by GitHub
parent 670f24a4af
commit fdfd923ac6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 1 deletions

View File

@ -38,7 +38,8 @@ public enum ElementModifier {
SYNCHRONIZED, SYNCHRONIZED,
TRANSIENT, TRANSIENT,
VARARGS, VARARGS,
VOLATILE; VOLATILE,
RECORD;
public static int pack(Set<ElementModifier> elementModifiers) { public static int pack(Set<ElementModifier> elementModifiers) {
ElementModifier[] knownModifiers = ElementModifier.values(); ElementModifier[] knownModifiers = ElementModifier.values();

View File

@ -505,6 +505,9 @@ public class Parser {
member.getModifiers().add(ElementModifier.VOLATILE); member.getModifiers().add(ElementModifier.VOLATILE);
} }
} }
if ((access & Opcodes.ACC_RECORD) != 0) {
member.getModifiers().add(ElementModifier.RECORD);
}
} }
private void parseAnnotations(AnnotationContainer annotations, List<AnnotationNode> visibleAnnotations, private void parseAnnotations(AnnotationContainer annotations, List<AnnotationNode> visibleAnnotations,

View File

@ -30,6 +30,8 @@ public interface ReflectClass<T> extends ReflectAnnotatedElement {
boolean isEnum(); boolean isEnum();
boolean isRecord();
T[] getEnumConstants(); T[] getEnumConstants();
int getModifiers(); int getModifiers();

View File

@ -86,6 +86,12 @@ public class ReflectClassImpl<T> implements ReflectClass<T> {
return classReader != null && classReader.readModifiers().contains(ElementModifier.ENUM); return classReader != null && classReader.readModifiers().contains(ElementModifier.ENUM);
} }
@Override
public boolean isRecord() {
resolve();
return classReader != null && classReader.readModifiers().contains(ElementModifier.RECORD);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public T[] getEnumConstants() { public T[] getEnumConstants() {

View File

@ -26,6 +26,8 @@ import org.teavm.model.ElementReader;
import org.teavm.model.ValueType; import org.teavm.model.ValueType;
public class ReflectContext { public class ReflectContext {
private static final int RECORD = 0x10000;
private ClassReaderSource classSource; private ClassReaderSource classSource;
private ClassHierarchy hierarchy; private ClassHierarchy hierarchy;
private Map<ValueType, ReflectClassImpl<?>> classes = new HashMap<>(); private Map<ValueType, ReflectClassImpl<?>> classes = new HashMap<>();
@ -108,6 +110,9 @@ public class ReflectContext {
if (modifierSet.contains(ElementModifier.VOLATILE)) { if (modifierSet.contains(ElementModifier.VOLATILE)) {
modifiers |= Modifier.VOLATILE; modifiers |= Modifier.VOLATILE;
} }
if (modifierSet.contains(ElementModifier.RECORD)) {
modifiers |= RECORD;
}
return modifiers; return modifiers;
} }
} }