Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7903788: preparation towards json configuration for jextract tool #257

Closed
wants to merge 8 commits into from
19 changes: 3 additions & 16 deletions src/main/java/org/openjdk/jextract/json/JSONObjects.java
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.RecordComponent;
import java.lang.reflect.WildcardType;
import java.lang.reflect.Type;
import java.io.File;
import java.net.MalformedURLException;
@@ -128,7 +127,7 @@ public static JSONObject from(Record record) {
Class<? extends Record> cls = record.getClass();
Map<String, JSONValue> props = new LinkedHashMap<>();
for (RecordComponent rc : cls.getRecordComponents()) {
props.put(rc.getName(), getRecordProperty(record, rc));
props.put(rc.getName(), getRecordComponentValue(record, rc));
}

return new JSONObject(props);
@@ -356,19 +355,7 @@ private static Type getSecondTypeArgument(ParameterizedType pt) {

private static Type getNthTypeArgument(ParameterizedType pt, int n) {
Type[] typeArgs = pt.getActualTypeArguments();
Type nthType = typeArgs.length > n ? typeArgs[n] : Object.class;
if (nthType instanceof WildcardType wt) {
Type[] upper = wt.getUpperBounds();
Type[] lower = wt.getLowerBounds();
if (upper.length > 0) {
nthType = upper[0];
} else if (lower.length > 0) {
nthType = lower[0];
} else {
nthType = Object.class;
}
}
return nthType;
return typeArgs.length > n ? typeArgs[n] : Object.class;
}

// record helpers
@@ -387,7 +374,7 @@ private static Constructor<? extends Record> getRecordConstructor(Class<? extend
}

// get the Record component value as a JSONValue
private static JSONValue getRecordProperty(Record record, RecordComponent rc) {
private static JSONValue getRecordComponentValue(Record record, RecordComponent rc) {
Object value = null;
try {
value = rc.getAccessor().invoke(record);