Exemplo n.º 1
0
        public byte[] createType(Library typeSystem)
        {
            checkCreated();
            this.created = true;
            var classWriter = new ClassWriterNoReflection(typeSystem, ClassWriter.COMPUTE_FRAMES);

            classWriter.visit(Opcodes.V1_6, modifiers, getFullName(), ReflectionHelper.getClassSignature(this),
                              baseType.getFullName(), getTypeNames(interfaces));
            if (sourceFile != null || sourceDebugExtension != null)
            {
                classWriter.visitSource(sourceFile, sourceDebugExtension);
            }
            foreach (var a in annotations)
            {
                a.accept(classWriter.visitAnnotation(a.Type.Descriptor, a.IsRuntimeVisible));
            }

            if (declaringType != null)
            {
                classWriter.visitInnerClass(FullName, declaringType.FullName, FullName.substring(FullName.lastIndexOf('$') + 1), modifiers);
            }

            foreach (var t in nestedTypes)
            {
                classWriter.visitInnerClass(t.FullName, FullName, t.FullName.substring(t.FullName.lastIndexOf('$') + 1), t.NestedModifiers);
            }

            foreach (var f in fields)
            {
                ((FieldBuilder)f).accept(classWriter.visitField(f.modifiers, f.Name, f.Descriptor, f.Signature, f.Value));
            }

            foreach (var m in methods)
            {
                if (!m.IsExcludedFromCompilation)
                {
                    ((MethodBuilder)m).accept(classWriter.visitMethod(m.Modifiers, m.Name, m.Descriptor,
                                                                      m.Signature, getTypeNames(m.Exceptions)));
                }
            }

            classWriter.visitEnd();
            return(classWriter.toByteArray());
        }
        public byte[] createType(Library typeSystem) {
            checkCreated();
            this.created = true;
            var classWriter = new ClassWriterNoReflection(typeSystem, ClassWriter.COMPUTE_FRAMES);
            classWriter.visit(Opcodes.V1_6, modifiers, getFullName(), ReflectionHelper.getClassSignature(this),
                baseType.getFullName(), getTypeNames(interfaces));
            if (sourceFile != null || sourceDebugExtension != null) {
                classWriter.visitSource(sourceFile, sourceDebugExtension);
            }
            foreach (var a in annotations) {
                a.accept(classWriter.visitAnnotation(a.Type.Descriptor, a.IsRuntimeVisible));
            }

            if (declaringType != null) {
                classWriter.visitInnerClass(FullName, declaringType.FullName, FullName.substring(FullName.lastIndexOf('$') + 1), modifiers);
            }
            
            foreach (var t in nestedTypes) {
                classWriter.visitInnerClass(t.FullName, FullName, t.FullName.substring(t.FullName.lastIndexOf('$') + 1), t.NestedModifiers);
            }
            
            foreach (var f in fields) {
                ((FieldBuilder)f).accept(classWriter.visitField(f.modifiers, f.Name, f.Descriptor, f.Signature, f.Value));
            }
            
            foreach (var m in methods) {
                if (!m.IsExcludedFromCompilation) {
                    ((MethodBuilder)m).accept(classWriter.visitMethod(m.Modifiers, m.Name, m.Descriptor,
                            m.Signature, getTypeNames(m.Exceptions)));
                }
            }
            
            classWriter.visitEnd();
            return classWriter.toByteArray();
        }