@@ -40,10 +40,12 @@ public class AttributeInfo {
40
40
public const string ConstantValue = "ConstantValue" ;
41
41
public const string Deprecated = "Deprecated" ;
42
42
public const string Exceptions = "Exceptions" ;
43
+ public const string EnclosingMethod = "EnclosingMethod" ;
43
44
public const string InnerClasses = "InnerClasses" ;
44
45
public const string LocalVariableTable = "LocalVariableTable" ;
45
46
public const string MethodParameters = "MethodParameters" ;
46
47
public const string Signature = "Signature" ;
48
+ public const string SourceFile = "SourceFile" ;
47
49
public const string StackMapTable = "StackMapTable" ;
48
50
49
51
ushort nameIndex ;
@@ -69,11 +71,13 @@ public string Name {
69
71
{ typeof ( CodeAttribute ) , Code } ,
70
72
{ typeof ( ConstantValueAttribute ) , ConstantValue } ,
71
73
{ typeof ( DeprecatedAttribute ) , Deprecated } ,
74
+ { typeof ( EnclosingMethodAttribute ) , EnclosingMethod } ,
72
75
{ typeof ( ExceptionsAttribute ) , Exceptions } ,
73
76
{ typeof ( InnerClassesAttribute ) , InnerClasses } ,
74
77
{ typeof ( LocalVariableTableAttribute ) , LocalVariableTable } ,
75
78
{ typeof ( MethodParametersAttribute ) , MethodParameters } ,
76
79
{ typeof ( SignatureAttribute ) , Signature } ,
80
+ { typeof ( SourceFileAttribute ) , SourceFile } ,
77
81
{ typeof ( StackMapTableAttribute ) , StackMapTable } ,
78
82
} ;
79
83
@@ -100,11 +104,13 @@ static AttributeInfo CreateAttribute (string name, ConstantPool constantPool, us
100
104
case Code : return new CodeAttribute ( constantPool , nameIndex , stream ) ;
101
105
case ConstantValue : return new ConstantValueAttribute ( constantPool , nameIndex , stream ) ;
102
106
case Deprecated : return new DeprecatedAttribute ( constantPool , nameIndex , stream ) ;
107
+ case EnclosingMethod : return new EnclosingMethodAttribute ( constantPool , nameIndex , stream ) ;
103
108
case Exceptions : return new ExceptionsAttribute ( constantPool , nameIndex , stream ) ;
104
109
case InnerClasses : return new InnerClassesAttribute ( constantPool , nameIndex , stream ) ;
105
110
case LocalVariableTable : return new LocalVariableTableAttribute ( constantPool , nameIndex , stream ) ;
106
111
case MethodParameters : return new MethodParametersAttribute ( constantPool , nameIndex , stream ) ;
107
112
case Signature : return new SignatureAttribute ( constantPool , nameIndex , stream ) ;
113
+ case SourceFile : return new SourceFileAttribute ( constantPool , nameIndex , stream ) ;
108
114
case StackMapTable : return new StackMapTableAttribute ( constantPool , nameIndex , stream ) ;
109
115
default : return new UnknownAttribute ( constantPool , nameIndex , stream ) ;
110
116
}
@@ -221,6 +227,33 @@ public override string ToString ()
221
227
}
222
228
}
223
229
230
+ // https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.7
231
+ public sealed class EnclosingMethodAttribute : AttributeInfo {
232
+
233
+ ushort classIndex , methodIndex ;
234
+
235
+ public ConstantPoolClassItem Class {
236
+ get { return ( ConstantPoolClassItem ) ConstantPool [ classIndex ] ; }
237
+ }
238
+
239
+ public ConstantPoolNameAndTypeItem Method {
240
+ get { return methodIndex == 0 ? null : ( ConstantPoolNameAndTypeItem ) ConstantPool [ methodIndex ] ; }
241
+ }
242
+
243
+ public EnclosingMethodAttribute ( ConstantPool constantPool , ushort nameIndex , Stream stream )
244
+ : base ( constantPool , nameIndex , stream )
245
+ {
246
+ var length = stream . ReadNetworkUInt32 ( ) ;
247
+ classIndex = stream . ReadNetworkUInt16 ( ) ;
248
+ methodIndex = stream . ReadNetworkUInt16 ( ) ;
249
+ }
250
+
251
+ public override string ToString ( )
252
+ {
253
+ return $ "EnclosingMethod({ Class } , { Method } )";
254
+ }
255
+ }
256
+
224
257
// http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.5
225
258
public sealed class ExceptionsAttribute : AttributeInfo {
226
259
@@ -483,6 +516,29 @@ public override string ToString ()
483
516
}
484
517
}
485
518
519
+ // https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.10
520
+ public sealed class SourceFileAttribute : AttributeInfo {
521
+
522
+ ushort sourceFileIndex ;
523
+
524
+ public string FileName {
525
+ get { return ( ( ConstantPoolUtf8Item ) ConstantPool [ sourceFileIndex ] ) . Value ; }
526
+ }
527
+
528
+ public SourceFileAttribute ( ConstantPool constantPool , ushort nameIndex , Stream stream )
529
+ : base ( constantPool , nameIndex , stream )
530
+ {
531
+ var length = stream . ReadNetworkUInt32 ( ) ;
532
+ sourceFileIndex = stream . ReadNetworkUInt16 ( ) ;
533
+ }
534
+
535
+ public override string ToString ( )
536
+ {
537
+ return $ "SourceFile('{ FileName } ')";
538
+ }
539
+ }
540
+
541
+
486
542
// http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.4
487
543
public sealed class StackMapTableAttribute : AttributeInfo {
488
544
0 commit comments