Skip to content

Commit

Permalink
Merge pull request #421 from Ladicek/canonical-record-constructor
Browse files Browse the repository at this point in the history
Rename ClassInfo.canonicalConstructor() to canonicalRecordConstructor()
  • Loading branch information
Ladicek authored Aug 8, 2024
2 parents 333ceef + 4402134 commit dc931b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions core/src/main/java/org/jboss/jandex/ClassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -757,13 +757,13 @@ public final List<MethodInfo> constructors() {
/**
* Returns the canonical constructor of this record. If this class is not a record, returns {@code null}.
* <p>
* Note that this method has the same limitations as {@link #unsortedRecordComponents()}. That is,
* at most 256 record components may be present, and an assumption is made that bytecode order
* of record components corresponds to the declaration order.
* Note that this method has the same limitations as {@link #recordComponentsInDeclarationOrder()}.
* That is, at most 256 record components may be present, and an assumption is made that bytecode
* order of record components corresponds to the declaration order.
*
* @return the canonical constructor of this record, or {@code null} if this class is not a record
*/
public MethodInfo canonicalConstructor() {
public MethodInfo canonicalRecordConstructor() {
if (!isRecord()) {
return null;
}
Expand Down Expand Up @@ -955,7 +955,7 @@ public final RecordComponentInfo recordComponent(String name) {
* If this class is not a record, returns an empty list.
* <p>
* Note that the result <em>doesn't</em> have any guaranteed order. If you need
* declaration order, use {@link #unsortedRecordComponents()}.
* declaration order, use {@link #recordComponentsInDeclarationOrder()}.
*
* @return immutable list of record components
*/
Expand Down
32 changes: 16 additions & 16 deletions core/src/test/java/org/jboss/jandex/test/RecordTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,47 +158,47 @@ public void testRecordSignatureProcessed() {
public void canonicalCtor() {
ClassInfo rec = index.getClassByName("test.RecordWithNoComponentsAndDefaultCanonicalCtor");
assertEquals(1, rec.constructors().size());
assertEquals(rec.constructors().get(0), rec.canonicalConstructor());
assertEquals(rec.constructors().get(0), rec.canonicalRecordConstructor());

rec = index.getClassByName("test.RecordWithNoComponentsAndCompactCanonicalCtor");
assertEquals(1, rec.constructors().size());
assertEquals(rec.constructors().get(0), rec.canonicalConstructor());
assertEquals(rec.constructors().get(0), rec.canonicalRecordConstructor());

rec = index.getClassByName("test.RecordWithNoComponentsAndCustomCanonicalCtor");
assertEquals(1, rec.constructors().size());
assertEquals(rec.constructors().get(0), rec.canonicalConstructor());
assertEquals(rec.constructors().get(0), rec.canonicalRecordConstructor());

rec = index.getClassByName("test.RecordWithDefaultCanonicalCtor");
assertEquals(1, rec.constructors().size());
assertEquals(rec.constructors().get(0), rec.canonicalConstructor());
assertEquals(rec.constructors().get(0), rec.canonicalRecordConstructor());

rec = index.getClassByName("test.RecordWithCompactCanonicalCtor");
assertEquals(1, rec.constructors().size());
assertEquals(rec.constructors().get(0), rec.canonicalConstructor());
assertEquals(rec.constructors().get(0), rec.canonicalRecordConstructor());

rec = index.getClassByName("test.RecordWithCustomCanonicalCtor");
assertEquals(1, rec.constructors().size());
assertEquals(rec.constructors().get(0), rec.canonicalConstructor());
assertEquals(rec.constructors().get(0), rec.canonicalRecordConstructor());

rec = index.getClassByName("test.RecordWithMultipleCtorsAndDefaultCanonicalCtor");
assertEquals(4, rec.constructors().size());
assertEquals(2, rec.canonicalConstructor().parametersCount());
assertEquals(PrimitiveType.INT, rec.canonicalConstructor().parameterType(0));
assertEquals(ClassType.create(String.class), rec.canonicalConstructor().parameterType(1));
assertEquals(2, rec.canonicalRecordConstructor().parametersCount());
assertEquals(PrimitiveType.INT, rec.canonicalRecordConstructor().parameterType(0));
assertEquals(ClassType.create(String.class), rec.canonicalRecordConstructor().parameterType(1));

rec = index.getClassByName("test.RecordWithMultipleCtorsAndCompactCanonicalCtor");
assertEquals(4, rec.constructors().size());
assertEquals(2, rec.canonicalConstructor().parametersCount());
assertEquals(PrimitiveType.INT, rec.canonicalConstructor().parameterType(0));
assertEquals(ClassType.create(String.class), rec.canonicalConstructor().parameterType(1));
assertEquals(2, rec.canonicalRecordConstructor().parametersCount());
assertEquals(PrimitiveType.INT, rec.canonicalRecordConstructor().parameterType(0));
assertEquals(ClassType.create(String.class), rec.canonicalRecordConstructor().parameterType(1));

rec = index.getClassByName("test.RecordWithMultipleCtorsAndCustomCanonicalCtor");
assertEquals(4, rec.constructors().size());
assertEquals(2, rec.canonicalConstructor().parametersCount());
assertEquals(PrimitiveType.INT, rec.canonicalConstructor().parameterType(0));
assertEquals(ClassType.create(String.class), rec.canonicalConstructor().parameterType(1));
assertEquals(2, rec.canonicalRecordConstructor().parametersCount());
assertEquals(PrimitiveType.INT, rec.canonicalRecordConstructor().parameterType(0));
assertEquals(ClassType.create(String.class), rec.canonicalRecordConstructor().parameterType(1));

assertNull(index.getClassByName(RecordTestCase.class).canonicalConstructor());
assertNull(index.getClassByName(RecordTestCase.class).canonicalRecordConstructor());
}

private Index buildIndex() throws IOException {
Expand Down

0 comments on commit dc931b6

Please sign in to comment.