Skip to content

Commit

Permalink
FormatCLASS - JVM 8 Runtime Type Annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
amosshi committed May 31, 2016
1 parent 127647f commit 0bf7412
Show file tree
Hide file tree
Showing 50 changed files with 847 additions and 184 deletions.
4 changes: 2 additions & 2 deletions BinaryInternalsViewer/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
Expand Down
4 changes: 2 additions & 2 deletions CommonLib/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
Expand Down
4 changes: 2 additions & 2 deletions FormatBMP/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
Expand Down
4 changes: 2 additions & 2 deletions FormatCLASS/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ javac.compilerargs=
javac.deprecation=true
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ protected Annotation(final PosDataInputStream posDataInputStream)
throws IOException, FileFormatException {
this.startPos = posDataInputStream.getPos();

this.type_index = new u2(posDataInputStream.readUnsignedShort());
this.num_element_value_pairs = new u2(posDataInputStream.readUnsignedShort());
this.type_index = new u2(posDataInputStream);
this.num_element_value_pairs = new u2(posDataInputStream);
if (this.num_element_value_pairs.value > 0) {
this.element_value_pairs = new ElementValuePair[this.num_element_value_pairs.value];
for (int i = 0; i < this.num_element_value_pairs.value; i++) {
Expand Down Expand Up @@ -93,7 +93,7 @@ protected ElementValuePair(final PosDataInputStream posDataInputStream)
throws IOException, FileFormatException {
this.startPos = posDataInputStream.getPos();

this.element_name_index = new u2(posDataInputStream.readUnsignedShort());
this.element_name_index = new u2(posDataInputStream);
this.value = new ElementValue(posDataInputStream);

this.length = posDataInputStream.getPos() - this.startPos;
Expand Down Expand Up @@ -182,7 +182,7 @@ protected ElementValue(final PosDataInputStream posDataInputStream)
|| this.tag == TagEnum.S.value
|| this.tag == TagEnum.Z.value
|| this.tag == TagEnum.s.value) {
this.union_const_value_index = new u2(posDataInputStream.readUnsignedShort());
this.union_const_value_index = new u2(posDataInputStream);
this.union_enum_const_value = null;
this.union_class_info_index = null;
this.union_annotation_value = null;
Expand All @@ -198,7 +198,7 @@ protected ElementValue(final PosDataInputStream posDataInputStream)
} else if (this.tag == TagEnum.c.value) {
this.union_const_value_index = null;
this.union_enum_const_value = null;
this.union_class_info_index = new u2(posDataInputStream.readUnsignedShort());
this.union_class_info_index = new u2(posDataInputStream);
this.union_annotation_value = null;
this.union_array_value = null;

Expand Down Expand Up @@ -339,8 +339,8 @@ protected EnumConstValue(final PosDataInputStream posDataInputStream)
this.startPos = posDataInputStream.getPos();
this.length = LENGTH;

this.type_name_index = new u2(posDataInputStream.readUnsignedShort());
this.const_name_index = new u2(posDataInputStream.readUnsignedShort());
this.type_name_index = new u2(posDataInputStream);
this.const_name_index = new u2(posDataInputStream);
}
}

Expand All @@ -353,7 +353,7 @@ protected ArrayValue(final PosDataInputStream posDataInputStream)
throws IOException, FileFormatException {
this.startPos = posDataInputStream.getPos();

this.num_values = new u2(posDataInputStream.readUnsignedShort());
this.num_values = new u2(posDataInputStream);
if (this.num_values.value > 0) {
this.values = new ElementValue[this.num_values.value];
for (int i = 0; i < this.num_values.value; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class AttributeBootstrapMethods extends AttributeInfo {
throws java.io.IOException, FileFormatException {
super(nameIndex, type, posDataInputStream);

this.num_bootstrap_methods = new u2(posDataInputStream.readUnsignedShort());
this.num_bootstrap_methods = new u2(posDataInputStream);
if (this.num_bootstrap_methods.value > 0) {
this.bootstrap_methods = new BootstrapMethod[this.num_bootstrap_methods.value];
for (int i = 0; i < this.num_bootstrap_methods.value; i++) {
Expand Down Expand Up @@ -89,12 +89,12 @@ private BootstrapMethod(final PosDataInputStream posDataInputStream)
throws IOException {
super.startPos = posDataInputStream.getPos();

this.bootstrap_method_ref = new u2(posDataInputStream.readUnsignedShort());
this.num_bootstrap_arguments = new u2(posDataInputStream.readUnsignedShort());
this.bootstrap_method_ref = new u2(posDataInputStream);
this.num_bootstrap_arguments = new u2(posDataInputStream);
if (this.num_bootstrap_arguments.value > 0) {
this.bootstrap_arguments = new u2[this.num_bootstrap_arguments.value];
for (int i = 0; i < this.num_bootstrap_arguments.value; i++) {
this.bootstrap_arguments[i] = new u2(posDataInputStream.readUnsignedShort());
this.bootstrap_arguments[i] = new u2(posDataInputStream);
}
} else {
this.bootstrap_arguments = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ public class AttributeCode extends AttributeInfo {

int i;

this.max_stack = new u2(posDataInputStream.readUnsignedShort());
this.max_locals = new u2(posDataInputStream.readUnsignedShort());
this.code_length = new u4(posDataInputStream.readInt());
this.max_stack = new u2(posDataInputStream);
this.max_locals = new u2(posDataInputStream);
this.code_length = new u4(posDataInputStream);
this.code = new byte[this.code_length.value];
posDataInputStream.read(this.code);

this.exception_table_length = new u2(posDataInputStream.readUnsignedShort());
this.exception_table_length = new u2(posDataInputStream);
if (this.exception_table_length.value > 0) {
this.exceptionTable = new ExceptionTable[this.exception_table_length.value];
for (i = 0; i < this.exception_table_length.value; i++) {
this.exceptionTable[i] = new ExceptionTable(posDataInputStream);
}
}

this.attributes_count = new u2(posDataInputStream.readUnsignedShort());
this.attributes_count = new u2(posDataInputStream);
if (this.attributes_count.value > 0) {
this.attributes = new AttributeInfo[this.attributes_count.value];
for (i = 0; i < this.attributes_count.value; i++) {
Expand All @@ -100,7 +100,7 @@ public byte[] getCode() {
/**
* Get the {@link #code} parse result. This method will return an empty list
* if {@link #code} is <code>null</code>.
*
*
* @return Parsed {@link Opcode} list
*/
public List<Opcode.InstructionResult> parseCode() {
Expand Down Expand Up @@ -154,10 +154,10 @@ private ExceptionTable(final PosDataInputStream posDataInputStream)
this.startPos = posDataInputStream.getPos();
this.length = LENGTH;

this.start_pc = new u2(posDataInputStream.readUnsignedShort());
this.end_pc = new u2(posDataInputStream.readUnsignedShort());
this.handler_pc = new u2(posDataInputStream.readUnsignedShort());
this.catch_type = new u2(posDataInputStream.readUnsignedShort());
this.start_pc = new u2(posDataInputStream);
this.end_pc = new u2(posDataInputStream);
this.handler_pc = new u2(posDataInputStream);
this.catch_type = new u2(posDataInputStream);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class AttributeConstantValue extends AttributeInfo {
if (this.attribute_length.value != 2) {
throw new FileFormatException(String.format("The attribute_length of AttributeConstantValue is not 2, it is %d.", this.attribute_length.value));
}
this.constantvalue_index = new u2(posDataInputStream.readUnsignedShort());
this.constantvalue_index = new u2(posDataInputStream);

super.checkSize(posDataInputStream.getPos());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class AttributeEnclosingMethod extends AttributeInfo {
throws java.io.IOException, FileFormatException {
super(nameIndex, type, posDataInputStream);

this.class_index = new u2(posDataInputStream.readUnsignedShort());
this.method_index = new u2(posDataInputStream.readUnsignedShort());
this.class_index = new u2(posDataInputStream);
this.method_index = new u2(posDataInputStream);

super.checkSize(posDataInputStream.getPos());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public class AttributeExceptions extends AttributeInfo {
throws IOException, FileFormatException {
super(nameIndex, type, posDataInputStream);

this.number_of_exceptions = new u2(posDataInputStream.readUnsignedShort());
this.number_of_exceptions = new u2(posDataInputStream);
if (this.number_of_exceptions.value > 0) {
this.exception_index_table = new u2[this.number_of_exceptions.value];
for (int i = 0; i < this.number_of_exceptions.value; i++) {
this.exception_index_table[i] = new u2(posDataInputStream.readUnsignedShort());
this.exception_index_table[i] = new u2(posDataInputStream);
}
} else {
this.exception_index_table = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public class AttributeInfo extends FileComponent {
super.startPos = posDataInputStream.getPos() - 2;

this.name = name;
this.attribute_name_index = new u2(nameIndex.value);
this.attribute_length = new u4(posDataInputStream.readInt());
this.attribute_name_index = nameIndex;
this.attribute_length = new u4(posDataInputStream);

super.length = this.attribute_length.value + 6;
}
Expand All @@ -84,7 +84,7 @@ static AttributeInfo parse(
throws IOException, FileFormatException {
AttributeInfo attr;

final u2 attrNameIndex = new u2(posDataInputStream.readUnsignedShort());
final u2 attrNameIndex = new u2(posDataInputStream);
if (CPInfo.ConstantType.CONSTANT_Utf8.tag == cp[attrNameIndex.value].tag.value) {
final String type = ((ConstantUtf8Info) cp[attrNameIndex.value]).getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AttributeInnerClasses extends AttributeInfo {
throws IOException, FileFormatException {
super(nameIndex, type, posDataInputStream);

this.number_of_classes = new u2(posDataInputStream.readUnsignedShort());
this.number_of_classes = new u2(posDataInputStream);
if (this.number_of_classes.value > 0) {
this.classes = new Class[this.number_of_classes.value];
for (int i = 0; i < this.number_of_classes.value; i++) {
Expand Down Expand Up @@ -95,10 +95,10 @@ private Class(final PosDataInputStream posDataInputStream)
this.startPos = posDataInputStream.getPos();
this.length = LENGTH;

this.inner_class_info_index = new u2(posDataInputStream.readUnsignedShort());
this.outer_class_info_index = new u2(posDataInputStream.readUnsignedShort());
this.inner_name_index = new u2(posDataInputStream.readUnsignedShort());
this.inner_class_access_flags = new u2(posDataInputStream.readUnsignedShort());
this.inner_class_info_index = new u2(posDataInputStream);
this.outer_class_info_index = new u2(posDataInputStream);
this.inner_name_index = new u2(posDataInputStream);
this.inner_class_access_flags = new u2(posDataInputStream);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AttributeLineNumberTable extends AttributeInfo {
throws IOException, FileFormatException {
super(nameIndex, type, posDataInputStream);

this.line_number_table_length = new u2(posDataInputStream.readUnsignedShort());
this.line_number_table_length = new u2(posDataInputStream);
if (this.line_number_table_length.value > 0) {
this.lineNumberTable = new LineNumberTable[this.line_number_table_length.value];
for (int i = 0; i < this.line_number_table_length.value; i++) {
Expand Down Expand Up @@ -87,8 +87,8 @@ private LineNumberTable(final PosDataInputStream posDataInputStream)
this.startPos = posDataInputStream.getPos();
this.length = LENGTH;

this.start_pc = new u2(posDataInputStream.readUnsignedShort());
this.line_number = new u2(posDataInputStream.readUnsignedShort());
this.start_pc = new u2(posDataInputStream);
this.line_number = new u2(posDataInputStream);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class AttributeLocalVariableTable extends AttributeInfo {
throws IOException, FileFormatException {
super(nameIndex, type, posDataInputStream);

this.local_variable_table_length = new u2(posDataInputStream.readUnsignedShort());
this.local_variable_table_length = new u2(posDataInputStream);
if (this.local_variable_table_length.value > 0) {
this.localVariableTable = new LocalVariableTable[this.local_variable_table_length.value];
for (int i = 0; i < this.local_variable_table_length.value; i++) {
Expand Down Expand Up @@ -124,11 +124,11 @@ private LocalVariableTable(final PosDataInputStream posDataInputStream)
super.startPos = posDataInputStream.getPos();
super.length = LENGTH;

this.start_pc = new u2(posDataInputStream.readUnsignedShort());
this.length = new u2(posDataInputStream.readUnsignedShort());
this.name_index = new u2(posDataInputStream.readUnsignedShort());
this.descriptor_index = new u2(posDataInputStream.readUnsignedShort());
this.index = new u2(posDataInputStream.readUnsignedShort());
this.start_pc = new u2(posDataInputStream);
this.length = new u2(posDataInputStream);
this.name_index = new u2(posDataInputStream);
this.descriptor_index = new u2(posDataInputStream);
this.index = new u2(posDataInputStream);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class AttributeLocalVariableTypeTable extends AttributeInfo {
throws java.io.IOException, FileFormatException {
super(nameIndex, type, posDataInputStream);

this.local_variable_type_table_length = new u2(posDataInputStream.readUnsignedShort());
this.local_variable_type_table_length = new u2(posDataInputStream);
if (this.local_variable_type_table_length.value > 0) {
this.local_variable_type_table = new LocalVariableTypeTable[this.local_variable_type_table_length.value];
for (int i = 0; i < this.local_variable_type_table_length.value; i++) {
Expand Down Expand Up @@ -97,11 +97,11 @@ protected LocalVariableTypeTable(final PosDataInputStream posDataInputStream)
super.startPos = posDataInputStream.getPos();
super.length = LENGTH;

this.start_pc = new u2(posDataInputStream.readUnsignedShort());
this.length = new u2(posDataInputStream.readUnsignedShort());
this.name_index = new u2(posDataInputStream.readUnsignedShort());
this.signature_index = new u2(posDataInputStream.readUnsignedShort());
this.index = new u2(posDataInputStream.readUnsignedShort());
this.start_pc = new u2(posDataInputStream);
this.length = new u2(posDataInputStream);
this.name_index = new u2(posDataInputStream);
this.signature_index = new u2(posDataInputStream);
this.index = new u2(posDataInputStream);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AttributeRuntimeAnnotations extends AttributeInfo {
throws java.io.IOException, FileFormatException {
super(nameIndex, type, posDataInputStream);

this.num_annotations = new u2(posDataInputStream.readUnsignedShort());
this.num_annotations = new u2(posDataInputStream);
if (this.num_annotations.value > 0) {
this.annotations = new Annotation[this.num_annotations.value];
for (int i = 0; i < this.num_annotations.value; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.freeinternals.format.classfile;

import java.io.IOException;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.format.FileFormatException;

/**
* The RuntimeInvisibleTypeAnnotations attribute records run-time invisible
* annotations on types used in the corresponding declaration of a class, field,
* or method, or in an expression in the corresponding method body. The
* RuntimeInvisibleTypeAnnotations attribute also records annotations on type
* parameter declarations of generic classes, interfaces, methods, and
* constructors.
*
* The RuntimeInvisibleTypeAnnotations attribute has the following format:
* <pre>
* RuntimeInvisibleTypeAnnotations_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u2 num_annotations;
* type_annotation annotations[num_annotations];
* }
* </pre>
*
* @author Amos Shi
* @since JDK 8.0
* @see <a
* href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.21">
* VM Spec: The RuntimeInvisibleTypeAnnotations Attribute
* </a>
*/
public class AttributeRuntimeInvisibleTypeAnnotations extends AttributeRuntimeTypeAnnotations {

public AttributeRuntimeInvisibleTypeAnnotations(
u2 nameIndex,
String name,
PosDataInputStream posDataInputStream)
throws IOException, FileFormatException {
super(nameIndex, name, posDataInputStream);
}
}
Loading

0 comments on commit 0bf7412

Please sign in to comment.