Skip to content

Commit

Permalink
Support Java Records in bytecode recorders
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jan 8, 2024
1 parent ba97483 commit 9d40de7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
package io.quarkus.deployment.recording;

import java.lang.reflect.Method;
import java.lang.reflect.RecordComponent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -19,6 +21,12 @@ final class PropertyUtils {
private static final Function<Class<?>, Property[]> FUNCTION = new Function<Class<?>, Property[]>() {
@Override
public Property[] apply(Class<?> type) {
if (type.isRecord()) {
RecordComponent[] recordComponents = type.getRecordComponents();
return Arrays.stream(recordComponents)
.map(rc -> new Property(rc.getName(), rc.getAccessor(), null, rc.getType())).toArray(Property[]::new);
}

List<Property> ret = new ArrayList<>();
Method[] methods = type.getMethods();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.extest.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.extest.runtime.records.TestRecord;
import io.quarkus.extest.runtime.records.TestRecordRecorder;

public class TestRecordProcessor {

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
public void record(TestRecordRecorder recorder) {
recorder.record(new TestRecord("foo", 100));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.quarkus.extest.runtime.records;

public record TestRecord(String name, int age) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.extest.runtime.records;

import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class TestRecordRecorder {

public static TestRecord testRecord;

public void record(TestRecord testRecord) {
TestRecordRecorder.testRecord = testRecord;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.it.extension;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import io.quarkus.extest.runtime.records.TestRecordRecorder;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class TestRecordRecorderTest {

@Test
public void test() {
assertEquals("foo", TestRecordRecorder.testRecord.name());
assertEquals(100, TestRecordRecorder.testRecord.age());
}
}

0 comments on commit 9d40de7

Please sign in to comment.