82 83 public final C withField(CharSequence name, T type) { 84 return withField(name, type, FB -> { 85 }); 86 } 87 88 public C withField(CharSequence name, T type, Consumer<? super FieldBuilder<S, T, byte[]>> fieldBuilder) { 89 FieldBuilder<S, T, byte[]> F = new FieldBuilder<>(name, type, poolHelper, typeHelper); 90 fieldBuilder.accept(F); 91 F.build(fields); 92 nfields++; 93 return thisBuilder(); 94 } 95 96 public final C withMethod(CharSequence name, T type) { 97 return withMethod(name, type, MB -> { 98 }); 99 } 100 101 public C withMethod(CharSequence name, T type, Consumer<? super MethodBuilder<S, T, byte[]>> methodBuilder) { 102 MethodBuilder<S, T, byte[]> M = new MethodBuilder<>(thisClass, name, type, poolHelper, typeHelper); 103 methodBuilder.accept(M); 104 M.build(methods); 105 nmethods++; 106 return thisBuilder(); 107 } 108 109 public byte[] build() { 110 addAnnotations(); 111 int thisClassIdx = poolHelper.putClass(thisClass); 112 byte[] poolBytes = poolHelper.entries(); 113 GrowableByteBuffer buf = new GrowableByteBuffer(); 114 buf.writeInt(0xCAFEBABE); 115 buf.writeChar(minorVersion); 116 buf.writeChar(majorVersion); 117 buf.writeChar(poolHelper.size() + 1); 118 buf.writeBytes(poolBytes); 119 buf.writeChar(flags); 120 buf.writeChar(thisClassIdx); 121 buf.writeChar(superclass); | 82 83 public final C withField(CharSequence name, T type) { 84 return withField(name, type, FB -> { 85 }); 86 } 87 88 public C withField(CharSequence name, T type, Consumer<? super FieldBuilder<S, T, byte[]>> fieldBuilder) { 89 FieldBuilder<S, T, byte[]> F = new FieldBuilder<>(name, type, poolHelper, typeHelper); 90 fieldBuilder.accept(F); 91 F.build(fields); 92 nfields++; 93 return thisBuilder(); 94 } 95 96 public final C withMethod(CharSequence name, T type) { 97 return withMethod(name, type, MB -> { 98 }); 99 } 100 101 public C withMethod(CharSequence name, T type, Consumer<? super MethodBuilder<S, T, byte[]>> methodBuilder) { 102 if (name.toString().contains(".")) { 103 throw new IllegalArgumentException("Illegal method name " + name); 104 } 105 MethodBuilder<S, T, byte[]> M = new MethodBuilder<>(thisClass, name, type, poolHelper, typeHelper); 106 methodBuilder.accept(M); 107 M.build(methods); 108 nmethods++; 109 return thisBuilder(); 110 } 111 112 public byte[] build() { 113 addAnnotations(); 114 int thisClassIdx = poolHelper.putClass(thisClass); 115 byte[] poolBytes = poolHelper.entries(); 116 GrowableByteBuffer buf = new GrowableByteBuffer(); 117 buf.writeInt(0xCAFEBABE); 118 buf.writeChar(minorVersion); 119 buf.writeChar(majorVersion); 120 buf.writeChar(poolHelper.size() + 1); 121 buf.writeBytes(poolBytes); 122 buf.writeChar(flags); 123 buf.writeChar(thisClassIdx); 124 buf.writeChar(superclass); |