Skip to content

Commit

Permalink
Sort members
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Apr 21, 2024
1 parent d18eae6 commit 8083fb5
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 160 deletions.
30 changes: 15 additions & 15 deletions src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,21 @@ public void visitParameterAnnotationEntry(final ParameterAnnotationEntry obj) {
stack.pop();
}

@Override
public void visitRecord(Record record) {
stack.push(record);
record.accept(visitor);
accept(record.getComponents());
stack.pop();
}

@Override
public void visitRecordComponent(RecordComponentInfo recordComponentInfo) {
stack.push(recordComponentInfo);
recordComponentInfo.accept(visitor);
stack.pop();
}

@Override
public void visitSignature(final Signature attribute) {
stack.push(attribute);
Expand Down Expand Up @@ -561,19 +576,4 @@ public void visitUnknown(final Unknown attribute) {
stack.pop();
}

@Override
public void visitRecord(Record record) {
stack.push(record);
record.accept(visitor);
accept(record.getComponents());
stack.pop();
}

@Override
public void visitRecordComponent(RecordComponentInfo recordComponentInfo) {
stack.push(recordComponentInfo);
recordComponentInfo.accept(visitor);
stack.pop();
}

}
48 changes: 24 additions & 24 deletions src/main/java/org/apache/bcel/classfile/JavaClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,19 @@ public int compareTo(final JavaClass obj) {
return getClassName().compareTo(obj.getClassName());
}

private void computeIsRecord() {
if (computedRecord) {
return;
}
for (final Attribute attribute : this.attributes) {
if (attribute instanceof Record) {
isRecord = true;
break;
}
}
this.computedRecord = true;
}

private void computeNestedTypeStatus() {
if (computedNestedTypeStatus) {
return;
Expand Down Expand Up @@ -743,6 +756,17 @@ public final boolean isNested() {
return this.isNested;
}

/**
* Tests whether this class was declared as a record
*
* @return true if a record attribute is present, false otherwise.
* @since 6.9.0
*/
public boolean isRecord() {
computeIsRecord();
return this.isRecord;
}

public final boolean isSuper() {
return (super.getAccessFlags() & Const.ACC_SUPER) != 0;
}
Expand Down Expand Up @@ -906,28 +930,4 @@ public String toString() {
}
return buf.toString();
}

/**
* Tests whether this class was declared as a record
*
* @return true if a record attribute is present, false otherwise.
* @since 6.9.0
*/
public boolean isRecord() {
computeIsRecord();
return this.isRecord;
}

private void computeIsRecord() {
if (computedRecord) {
return;
}
for (final Attribute attribute : this.attributes) {
if (attribute instanceof Record) {
isRecord = true;
break;
}
}
this.computedRecord = true;
}
}
20 changes: 10 additions & 10 deletions src/main/java/org/apache/bcel/classfile/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public final class Record extends Attribute {

private static final RecordComponentInfo[] EMPTY_RCI_ARRAY = new RecordComponentInfo[] {};

private static RecordComponentInfo[] readComponents(final DataInput input, final ConstantPool constantPool)
throws IOException {
final int classCount = input.readUnsignedShort();
final RecordComponentInfo[] components = new RecordComponentInfo[classCount];
for (int i = 0; i < classCount; i++) {
components[i] = new RecordComponentInfo(input, constantPool);
}
return components;
}

private RecordComponentInfo[] components;

/**
Expand All @@ -53,16 +63,6 @@ public final class Record extends Attribute {
this(nameIndex, length, readComponents(input, constantPool), constantPool);
}

private static RecordComponentInfo[] readComponents(final DataInput input, final ConstantPool constantPool)
throws IOException {
final int classCount = input.readUnsignedShort();
final RecordComponentInfo[] components = new RecordComponentInfo[classCount];
for (int i = 0; i < classCount; i++) {
components[i] = new RecordComponentInfo(input, constantPool);
}
return components;
}

/**
* Constructs a new instance using components.
*
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public RecordComponentInfo(final DataInput input, ConstantPool constantPool) thr
this.constantPool = constantPool;
}

@Override
public void accept(Visitor v) {
v.visitRecordComponent(this);
}

/**
* Dumps contents into a file stream in binary format.
*
Expand All @@ -70,18 +75,22 @@ public void dump(DataOutputStream file) throws IOException {
}
}

@Override
public void accept(Visitor v) {
v.visitRecordComponent(this);
/**
* Gets all attributes.
*
* @return all attributes.
*/
public Attribute[] getAttributes() {
return attributes;
}

/**
* Gets the name index.
* Gets the constant pool.
*
* @return index in constant pool of this record component name.
* @return Constant pool.
*/
public int getIndex() {
return index;
public ConstantPool getConstantPool() {
return constantPool;
}

/**
Expand All @@ -94,21 +103,12 @@ public int getDescriptorIndex() {
}

/**
* Gets all attributes.
*
* @return all attributes.
*/
public Attribute[] getAttributes() {
return attributes;
}

/**
* Gets the constant pool.
* Gets the name index.
*
* @return Constant pool.
* @return index in constant pool of this record component name.
*/
public ConstantPool getConstantPool() {
return constantPool;
public int getIndex() {
return index;
}

/**
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/org/apache/bcel/classfile/Visitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ default void visitNestMembers(final NestMembers obj) {
// empty
}

/**
* @since 6.0
*/
void visitParameterAnnotation(ParameterAnnotations obj);


/**
* @since 6.0
*/
void visitParameterAnnotationEntry(ParameterAnnotationEntry obj);

/**
* Visits a {@link Record} object.
*
Expand All @@ -217,16 +228,15 @@ default void visitRecord(final Record obj) {
// empty
}


/**
* @since 6.0
*/
void visitParameterAnnotation(ParameterAnnotations obj);

/**
* @since 6.0
* Visits a {@link RecordComponentInfo} object.
*
* @param record component to visit
* @since 6.9.0
*/
void visitParameterAnnotationEntry(ParameterAnnotationEntry obj);
default void visitRecordComponent(RecordComponentInfo record) {
// noop
}

void visitSignature(Signature obj);

Expand All @@ -250,14 +260,4 @@ default void visitStackMapType(final StackMapType obj) {

void visitUnknown(Unknown obj);

/**
* Visits a {@link RecordComponentInfo} object.
*
* @param record component to visit
* @since 6.9.0
*/
default void visitRecordComponent(RecordComponentInfo record) {
// noop
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,16 @@ public void visitParameterAnnotationEntry(final ParameterAnnotationEntry obj) {
tostring = toString(obj);
}

@Override
public void visitRecord(Record obj) {
tostring = toString(obj);
}

@Override
public void visitRecordComponent(RecordComponentInfo obj) {
tostring = toString(obj);
}

@Override
public void visitSignature(final Signature obj) {
tostring = toString(obj);
Expand Down Expand Up @@ -432,14 +442,4 @@ public void visitUnknown(final Unknown obj) {
tostring = toString(obj);
}

@Override
public void visitRecord(Record obj) {
tostring = toString(obj);
}

@Override
public void visitRecordComponent(RecordComponentInfo obj) {
tostring = toString(obj);
}

}
10 changes: 5 additions & 5 deletions src/test/java/org/apache/bcel/CounterVisitorTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public void testParameterAnnotationCount() {
assertEquals(0, getVisitor().parameterAnnotationCount, "parameterAnnotationCount");
}

@Test
public void testRecordCount() {
assertEquals(0, getVisitor().recordCount, "recordCount");
}

@Test
public void testSignatureCount() {
assertEquals(0, getVisitor().signatureAnnotationCount, "signatureAnnotationCount");
Expand Down Expand Up @@ -217,9 +222,4 @@ public void testSyntheticCount() {
public void testUnknownCount() {
assertEquals(0, getVisitor().unknownCount, "unknownCount");
}

@Test
public void testRecordCount() {
assertEquals(0, getVisitor().recordCount, "recordCount");
}
}
Loading

0 comments on commit 8083fb5

Please sign in to comment.