Skip to content

Commit 9e51f7a

Browse files
committed
add new files
1 parent 6be962f commit 9e51f7a

File tree

7 files changed

+454
-0
lines changed

7 files changed

+454
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* reserved comment block
3+
* DO NOT REMOVE OR ALTER!
4+
*/
5+
/*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
* The ASF licenses this file to You under the Apache License, Version 2.0
10+
* (the "License"); you may not use this file except in compliance with
11+
* the License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
package com.sun.org.apache.bcel.internal.classfile;
23+
24+
/**
25+
* Thrown when the BCEL attempts to read a class file and determines that a class is malformed or otherwise cannot be interpreted as a class file.
26+
*
27+
* @since 6.8.0
28+
*/
29+
public class InvalidMethodSignatureException extends ClassFormatException {
30+
31+
private static final long serialVersionUID = 1L;
32+
33+
/**
34+
* Constructs a new instance with the specified invalid signature as the message.
35+
*
36+
* @param signature The invalid signature is saved for later retrieval by the {@link #getMessage()} method.
37+
*/
38+
public InvalidMethodSignatureException(final String signature) {
39+
super(signature);
40+
}
41+
42+
/**
43+
* Constructs a new instance with the specified invalid signature as the message and a cause.
44+
*
45+
* @param signature The invalid signature is saved for later retrieval by the {@link #getMessage()} method.
46+
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). A {@code null} value is permitted, and indicates that
47+
* the cause is nonexistent or unknown.
48+
*/
49+
public InvalidMethodSignatureException(final String signature, final Throwable cause) {
50+
super(signature, cause);
51+
}
52+
53+
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* reserved comment block
3+
* DO NOT REMOVE OR ALTER!
4+
*/
5+
/*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
* The ASF licenses this file to You under the Apache License, Version 2.0
10+
* (the "License"); you may not use this file except in compliance with
11+
* the License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
package com.sun.org.apache.bcel.internal.classfile;
23+
24+
import java.io.DataInput;
25+
import java.io.DataOutputStream;
26+
import java.io.IOException;
27+
28+
import com.sun.org.apache.bcel.internal.Const;
29+
import com.sun.org.apache.bcel.internal.util.Args;
30+
31+
/**
32+
* Extends {@link Attribute} and records the classes and
33+
* interfaces that are authorized to claim membership in the nest hosted by the
34+
* current class or interface. There may be at most one Record attribute in a
35+
* ClassFile structure.
36+
*
37+
* @see Attribute
38+
* @since 6.9.0
39+
*/
40+
public final class Record extends Attribute {
41+
42+
private static final RecordComponentInfo[] EMPTY_RCI_ARRAY = {};
43+
44+
private static RecordComponentInfo[] readComponents(final DataInput input, final ConstantPool constantPool)
45+
throws IOException {
46+
final int classCount = input.readUnsignedShort();
47+
final RecordComponentInfo[] components = new RecordComponentInfo[classCount];
48+
for (int i = 0; i < classCount; i++) {
49+
components[i] = new RecordComponentInfo(input, constantPool);
50+
}
51+
return components;
52+
}
53+
54+
private RecordComponentInfo[] components;
55+
56+
/**
57+
* Constructs object from input stream.
58+
*
59+
* @param nameIndex Index in constant pool
60+
* @param length Content length in bytes
61+
* @param input Input stream
62+
* @param constantPool Array of constants
63+
* @throws IOException if an I/O error occurs.
64+
*/
65+
Record(final int nameIndex, final int length, final DataInput input, final ConstantPool constantPool)
66+
throws IOException {
67+
this(nameIndex, length, readComponents(input, constantPool), constantPool);
68+
}
69+
70+
/**
71+
* Constructs a new instance using components.
72+
*
73+
* @param nameIndex Index in constant pool
74+
* @param length Content length in bytes
75+
* @param classes Array of Record Component Info elements
76+
* @param constantPool Array of constants
77+
*/
78+
public Record(final int nameIndex, final int length, final RecordComponentInfo[] classes,
79+
final ConstantPool constantPool) {
80+
super(Const.ATTR_RECORD, nameIndex, length, constantPool);
81+
this.components = classes != null ? classes : EMPTY_RCI_ARRAY;
82+
Args.requireU2(this.components.length, "attributes.length");
83+
}
84+
85+
/**
86+
* Called by objects that are traversing the nodes of the tree implicitly
87+
* defined by the contents of a Java class. For example, the hierarchy of methods,
88+
* fields, attributes, etc. spawns a tree of objects.
89+
*
90+
* @param v Visitor object
91+
*/
92+
@Override
93+
public void accept(final Visitor v) {
94+
v.visitRecord(this);
95+
}
96+
97+
/**
98+
* Copies this instance and its components.
99+
*
100+
* @return a deep copy of this instance and its components.
101+
*/
102+
@Override
103+
public Attribute copy(final ConstantPool constantPool) {
104+
final Record c = (Record) clone();
105+
if (components.length > 0) {
106+
c.components = components.clone();
107+
}
108+
c.setConstantPool(constantPool);
109+
return c;
110+
}
111+
112+
/**
113+
* Dumps this instance into a file stream in binary format.
114+
*
115+
* @param file output stream.
116+
* @throws IOException if an I/O error occurs.
117+
*/
118+
@Override
119+
public void dump(final DataOutputStream file) throws IOException {
120+
super.dump(file);
121+
file.writeShort(components.length);
122+
for (final RecordComponentInfo component : components) {
123+
component.dump(file);
124+
}
125+
}
126+
127+
/**
128+
* Gets all the record components.
129+
*
130+
* @return array of Record Component Info elements.
131+
*/
132+
public RecordComponentInfo[] getComponents() {
133+
return components;
134+
}
135+
136+
/**
137+
* Converts this instance to a String suitable for debugging.
138+
*
139+
* @return String a String suitable for debugging.
140+
*/
141+
@Override
142+
public String toString() {
143+
final StringBuilder buf = new StringBuilder();
144+
buf.append("Record(");
145+
buf.append(components.length);
146+
buf.append("):\n");
147+
for (final RecordComponentInfo component : components) {
148+
buf.append(" ").append(component.toString()).append("\n");
149+
}
150+
return buf.substring(0, buf.length() - 1); // remove the last newline
151+
}
152+
153+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* reserved comment block
3+
* DO NOT REMOVE OR ALTER!
4+
*/
5+
/*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
* The ASF licenses this file to You under the Apache License, Version 2.0
10+
* (the "License"); you may not use this file except in compliance with
11+
* the License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
package com.sun.org.apache.bcel.internal.classfile;
22+
23+
import java.io.DataInput;
24+
import java.io.DataOutputStream;
25+
import java.io.IOException;
26+
27+
import com.sun.org.apache.bcel.internal.Const;
28+
29+
/**
30+
* Record component info from a record. Instances from this class maps
31+
* every component from a given record.
32+
*
33+
* @see <a href="https://docs.oracle.com/javase/specs/jvms/se14/preview/specs/records-jvms.html#jvms-4.7.30">
34+
* The Java Virtual Machine Specification, Java SE 14 Edition, Records (preview)</a>
35+
* @since 6.9.0
36+
*/
37+
public class RecordComponentInfo implements Node {
38+
39+
private final int index;
40+
private final int descriptorIndex;
41+
private final Attribute[] attributes;
42+
private final ConstantPool constantPool;
43+
44+
/**
45+
* Constructs a new instance from an input stream.
46+
*
47+
* @param input Input stream
48+
* @param constantPool Array of constants
49+
* @throws IOException if an I/O error occurs.
50+
*/
51+
public RecordComponentInfo(final DataInput input, final ConstantPool constantPool) throws IOException {
52+
this.index = input.readUnsignedShort();
53+
this.descriptorIndex = input.readUnsignedShort();
54+
final int attributesCount = input.readUnsignedShort();
55+
this.attributes = new Attribute[attributesCount];
56+
for (int j = 0; j < attributesCount; j++) {
57+
attributes[j] = Attribute.readAttribute(input, constantPool);
58+
}
59+
this.constantPool = constantPool;
60+
}
61+
62+
@Override
63+
public void accept(final Visitor v) {
64+
v.visitRecordComponent(this);
65+
}
66+
67+
/**
68+
* Dumps contents into a file stream in binary format.
69+
*
70+
* @param file Output file stream
71+
* @throws IOException if an I/O error occurs.
72+
*/
73+
public void dump(final DataOutputStream file) throws IOException {
74+
file.writeShort(index);
75+
file.writeShort(descriptorIndex);
76+
file.writeShort(attributes.length);
77+
for (final Attribute attribute : attributes) {
78+
attribute.dump(file);
79+
}
80+
}
81+
82+
/**
83+
* Gets all attributes.
84+
*
85+
* @return all attributes.
86+
*/
87+
public Attribute[] getAttributes() {
88+
return attributes;
89+
}
90+
91+
/**
92+
* Gets the constant pool.
93+
*
94+
* @return Constant pool.
95+
*/
96+
public ConstantPool getConstantPool() {
97+
return constantPool;
98+
}
99+
100+
/**
101+
* Gets the description index.
102+
*
103+
* @return index in constant pool of this record component descriptor.
104+
*/
105+
public int getDescriptorIndex() {
106+
return descriptorIndex;
107+
}
108+
109+
/**
110+
* Gets the name index.
111+
*
112+
* @return index in constant pool of this record component name.
113+
*/
114+
public int getIndex() {
115+
return index;
116+
}
117+
118+
/**
119+
* Converts this instance to a String suitable for debugging.
120+
*
121+
* @return a String suitable for debugging.
122+
*/
123+
@Override
124+
public String toString() {
125+
final StringBuilder buf = new StringBuilder();
126+
buf.append("RecordComponentInfo(");
127+
buf.append(constantPool.getConstantString(index, Const.CONSTANT_Utf8));
128+
buf.append(",");
129+
buf.append(constantPool.getConstantString(descriptorIndex, Const.CONSTANT_Utf8));
130+
buf.append(",");
131+
buf.append(attributes.length);
132+
buf.append("):\n");
133+
for (final Attribute attribute : attributes) {
134+
buf.append(" ").append(attribute.toString()).append("\n");
135+
}
136+
return buf.substring(0, buf.length() - 1); // remove the last newline
137+
}
138+
139+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* reserved comment block
3+
* DO NOT REMOVE OR ALTER!
4+
*/
5+
/*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
* The ASF licenses this file to You under the Apache License, Version 2.0
10+
* (the "License"); you may not use this file except in compliance with
11+
* the License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
/**
23+
* Classes that describe the structure of a Java class file and a class file parser.
24+
*/
25+
package com.sun.org.apache.bcel.internal.classfile;

0 commit comments

Comments
 (0)