Skip to content

Commit

Permalink
Merge pull request #38091 from geoand/bytecode-recording-records
Browse files Browse the repository at this point in the history
Support Java Records in bytecode recorders
  • Loading branch information
geoand committed Jan 9, 2024
2 parents 6e5c82e + 9d40de7 commit fca79fe
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 fca79fe

Please sign in to comment.