rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java
changeset 1898 cf6d5d357696
parent 1889 e1953d8b8338
     1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java	Sat Mar 19 10:31:13 2016 +0100
     1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java	Sun Mar 20 08:12:55 2016 +0100
     1.3 @@ -570,6 +570,7 @@
     1.4          private Hashtable indexHashAscii = new Hashtable();
     1.5          private String pkgPrefix = "";
     1.6          private int pkgPrefixLen = 0;
     1.7 +        private boolean hasEnclosingMethod;
     1.8  
     1.9          /**
    1.10           * Read classfile to disassemble.
    1.11 @@ -620,42 +621,45 @@
    1.12              attrs = new AttrData[attributes_count];
    1.13              for (int k = 0; k < attributes_count; k++) {
    1.14                  int name_cpx = in.readUnsignedShort();
    1.15 -                if (getTag(name_cpx) == CONSTANT_UTF8
    1.16 -                    && getString(name_cpx).equals("SourceFile")) {
    1.17 -                    if (in.readInt() != 2) {
    1.18 -                        throw new ClassFormatError("invalid attr length");
    1.19 +                if (getTag(name_cpx) == CONSTANT_UTF8) {
    1.20 +                    final String attrName = getString(name_cpx);
    1.21 +                    if (attrName.equals("SourceFile")) {
    1.22 +                        if (in.readInt() != 2) {
    1.23 +                            throw new ClassFormatError("invalid attr length");
    1.24 +                        }
    1.25 +                        source_cpx = in.readUnsignedShort();
    1.26 +                        AttrData attr = new AttrData(this);
    1.27 +                        attr.read(name_cpx);
    1.28 +                        attrs[k] = attr;
    1.29 +
    1.30 +                    } else if (attrName.equals("InnerClasses")) {
    1.31 +                        int length = in.readInt();
    1.32 +                        int num = in.readUnsignedShort();
    1.33 +                        if (2 + num * 8 != length) {
    1.34 +                            throw new ClassFormatError("invalid attr length");
    1.35 +                        }
    1.36 +                        innerClasses = new InnerClassData[num];
    1.37 +                        for (int j = 0; j < num; j++) {
    1.38 +                            InnerClassData innerClass = new InnerClassData(this);
    1.39 +                            innerClass.read(in);
    1.40 +                            innerClasses[j] = innerClass;
    1.41 +                        }
    1.42 +                        AttrData attr = new AttrData(this);
    1.43 +                        attr.read(name_cpx);
    1.44 +                        attrs[k] = attr;
    1.45 +                    } else if (attrName.equals("BootstrapMethods")) {
    1.46 +                        AttrData attr = new AttrData(this);
    1.47 +                        bootMethods = readBootstrapMethods(in);
    1.48 +                        attr.read(name_cpx);
    1.49 +                        attrs[k] = attr;
    1.50 +                    } else {
    1.51 +                        if (attrName.equals("EnclosingMethod")) {
    1.52 +                            hasEnclosingMethod = true;
    1.53 +                        }
    1.54 +                        AttrData attr = new AttrData(this);
    1.55 +                        attr.read(name_cpx, in);
    1.56 +                        attrs[k] = attr;
    1.57                      }
    1.58 -                    source_cpx = in.readUnsignedShort();
    1.59 -                    AttrData attr = new AttrData(this);
    1.60 -                    attr.read(name_cpx);
    1.61 -                    attrs[k] = attr;
    1.62 -
    1.63 -                } else if (getTag(name_cpx) == CONSTANT_UTF8
    1.64 -                    && getString(name_cpx).equals("InnerClasses")) {
    1.65 -                    int length = in.readInt();
    1.66 -                    int num = in.readUnsignedShort();
    1.67 -                    if (2 + num * 8 != length) {
    1.68 -                        throw new ClassFormatError("invalid attr length");
    1.69 -                    }
    1.70 -                    innerClasses = new InnerClassData[num];
    1.71 -                    for (int j = 0; j < num; j++) {
    1.72 -                        InnerClassData innerClass = new InnerClassData(this);
    1.73 -                        innerClass.read(in);
    1.74 -                        innerClasses[j] = innerClass;
    1.75 -                    }
    1.76 -                    AttrData attr = new AttrData(this);
    1.77 -                    attr.read(name_cpx);
    1.78 -                    attrs[k] = attr;
    1.79 -                } else if (getTag(name_cpx) == CONSTANT_UTF8
    1.80 -                    && getString(name_cpx).equals("BootstrapMethods")) {
    1.81 -                    AttrData attr = new AttrData(this);
    1.82 -                    bootMethods = readBootstrapMethods(in);
    1.83 -                    attr.read(name_cpx);
    1.84 -                    attrs[k] = attr;
    1.85 -                } else {
    1.86 -                    AttrData attr = new AttrData(this);
    1.87 -                    attr.read(name_cpx, in);
    1.88 -                    attrs[k] = attr;
    1.89                  }
    1.90              }
    1.91              in.close();
    1.92 @@ -876,6 +880,10 @@
    1.93              return access;
    1.94          }
    1.95  
    1.96 +        public boolean hasEnclosingMethod() {
    1.97 +            return hasEnclosingMethod;
    1.98 +        }
    1.99 +
   1.100          /**
   1.101           * Returns true if it is a class
   1.102           */