or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

builder.mdclassfile.mdcollections.mdfunctional.mdindex.mdsignatures.mdstream.md

builder.mddocs/

0

# Class File Builder Package

1

2

Programmatic construction of Java class files using the builder pattern. This package provides comprehensive tools for building ClassFile objects, module-info files, and managing mutable constant pools. All builders support fluent method chaining and ensure proper validation of class file structure.

3

4

## Capabilities

5

6

### ClassFileBuilder

7

8

Core builder for constructing standard Java class files with complete control over all class file elements.

9

10

```java { .api }

11

/**

12

* Builder for constructing ClassFile objects programmatically using fluent interface

13

*/

14

public class ClassFileBuilder {

15

/**

16

* Create new ClassFileBuilder with full parameter specification

17

* @param access_flags Class access flags (ACC_PUBLIC, ACC_FINAL, etc.)

18

* @param major_version Class file major version number

19

* @param minor_version Class file minor version number

20

* @param this_class Binary name of this class

21

* @param super_class Binary name of super class (null for java.lang.Object)

22

* @param interfaces Collection of interface binary names

23

*/

24

public ClassFileBuilder(int access_flags, int major_version, int minor_version,

25

String this_class, String super_class, Collection<String> interfaces);

26

27

/**

28

* Create new ClassFileBuilder with interface array

29

* @param access_flags Class access flags

30

* @param major_version Class file major version number

31

* @param minor_version Class file minor version number

32

* @param this_class Binary name of this class

33

* @param super_class Binary name of super class

34

* @param interfaces Array of interface binary names

35

*/

36

public ClassFileBuilder(int access_flags, int major_version, int minor_version,

37

String this_class, String super_class, String... interfaces);

38

39

/**

40

* Create new ClassFileBuilder with no interfaces

41

* @param access_flags Class access flags

42

* @param major_version Class file major version number

43

* @param minor_version Class file minor version number

44

* @param this_class Binary name of this class

45

* @param super_class Binary name of super class

46

*/

47

public ClassFileBuilder(int access_flags, int major_version, int minor_version,

48

String this_class, String super_class);

49

50

/**

51

* Create ClassFileBuilder from existing ClassFile for modification

52

* @param classFile Existing ClassFile to copy from

53

*/

54

public ClassFileBuilder(ClassFile classFile);

55

56

// Version control methods

57

/**

58

* Get minor version number

59

* @return Minor version number

60

*/

61

public int minor_version();

62

63

/**

64

* Set minor version number

65

* @param minor_version Minor version number

66

* @return This builder instance

67

*/

68

public ClassFileBuilder minor_version(int minor_version);

69

70

/**

71

* Get major version number

72

* @return Major version number

73

*/

74

public int major_version();

75

76

/**

77

* Set major version number

78

* @param major_version Major version number

79

* @return This builder instance

80

*/

81

public ClassFileBuilder major_version(int major_version);

82

83

// Constant pool management

84

/**

85

* Get mutable constant pool

86

* @return MutableConstantPool instance

87

*/

88

public MutableConstantPool constant_pool();

89

90

/**

91

* Set mutable constant pool

92

* @param constant_pool MutableConstantPool to use

93

* @return This builder instance

94

*/

95

public ClassFileBuilder constant_pool(MutableConstantPool constant_pool);

96

97

// Access flags

98

/**

99

* Get access flags

100

* @return Access flags value

101

*/

102

public int access();

103

104

/**

105

* Set access flags

106

* @param access Access flags (ACC_PUBLIC, ACC_FINAL, etc.)

107

* @return This builder instance

108

*/

109

public ClassFileBuilder access(int access);

110

111

// Class naming

112

/**

113

* Get this class name

114

* @return Binary name of this class

115

*/

116

public String this_class();

117

118

/**

119

* Set this class name

120

* @param this_class Binary name of this class

121

* @return This builder instance

122

*/

123

public ClassFileBuilder this_class(String this_class);

124

125

/**

126

* Get super class name

127

* @return Binary name of super class

128

*/

129

public String super_class();

130

131

/**

132

* Set super class name

133

* @param super_class Binary name of super class (null for java.lang.Object)

134

* @return This builder instance

135

*/

136

public ClassFileBuilder super_class(String super_class);

137

138

// Interface management

139

/**

140

* Get interfaces list

141

* @return Mutable list of interface binary names

142

*/

143

public List<String> interfaces();

144

145

/**

146

* Add single interface

147

* @param interfc Interface binary name

148

* @return This builder instance

149

*/

150

public ClassFileBuilder interfaces(String interfc);

151

152

/**

153

* Add interface array

154

* @param interfcs Array of interface binary names

155

* @return This builder instance

156

*/

157

public ClassFileBuilder interfaces(String[] interfcs);

158

159

/**

160

* Add interface collection

161

* @param interfcs Collection of interface binary names

162

* @return This builder instance

163

*/

164

public ClassFileBuilder interfaces(Collection<String> interfcs);

165

166

/**

167

* Add multiple interfaces

168

* @param interfc First interface binary name

169

* @param interfcs Additional interface binary names

170

* @return This builder instance

171

*/

172

public ClassFileBuilder interfaces(String interfc, String... interfcs);

173

174

// Field management

175

/**

176

* Get fields list

177

* @return Mutable list of FieldInfo objects

178

*/

179

public List<FieldInfo> fields();

180

181

/**

182

* Add or replace field (replaces existing field with same name and descriptor)

183

* @param field FieldInfo to add

184

* @return This builder instance

185

*/

186

public ClassFileBuilder fields(FieldInfo field);

187

188

/**

189

* Add field array

190

* @param fields Array of FieldInfo objects

191

* @return This builder instance

192

*/

193

public ClassFileBuilder fields(FieldInfo[] fields);

194

195

/**

196

* Add field collection

197

* @param fields Collection of FieldInfo objects

198

* @return This builder instance

199

*/

200

public ClassFileBuilder fields(Collection<FieldInfo> fields);

201

202

/**

203

* Add multiple fields

204

* @param field First FieldInfo

205

* @param fields Additional FieldInfo objects

206

* @return This builder instance

207

*/

208

public ClassFileBuilder fields(FieldInfo field, FieldInfo... fields);

209

210

// Method management

211

/**

212

* Get methods list

213

* @return Mutable list of MethodInfo objects

214

*/

215

public List<MethodInfo> methods();

216

217

/**

218

* Add or replace method (replaces existing method with same name and descriptor)

219

* @param method MethodInfo to add

220

* @return This builder instance

221

*/

222

public ClassFileBuilder methods(MethodInfo method);

223

224

/**

225

* Add method array

226

* @param methods Array of MethodInfo objects

227

* @return This builder instance

228

*/

229

public ClassFileBuilder methods(MethodInfo[] methods);

230

231

/**

232

* Add method collection

233

* @param methods Collection of MethodInfo objects

234

* @return This builder instance

235

*/

236

public ClassFileBuilder methods(Collection<MethodInfo> methods);

237

238

/**

239

* Add multiple methods

240

* @param method First MethodInfo

241

* @param methods Additional MethodInfo objects

242

* @return This builder instance

243

*/

244

public ClassFileBuilder methods(MethodInfo method, MethodInfo... methods);

245

246

// Attribute management

247

/**

248

* Get attributes list

249

* @return Mutable list of Attribute objects

250

*/

251

public List<Attribute> attributes();

252

253

/**

254

* Add attribute

255

* @param attribute Attribute to add

256

* @return This builder instance

257

*/

258

public ClassFileBuilder attributes(Attribute attribute);

259

260

/**

261

* Add attribute array

262

* @param attributes Array of Attribute objects

263

* @return This builder instance

264

*/

265

public ClassFileBuilder attributes(Attribute[] attributes);

266

267

/**

268

* Add attribute collection

269

* @param attributes Collection of Attribute objects

270

* @return This builder instance

271

*/

272

public ClassFileBuilder attributes(Collection<Attribute> attributes);

273

274

/**

275

* Add multiple attributes

276

* @param attribute First Attribute

277

* @param attributes Additional Attribute objects

278

* @return This builder instance

279

*/

280

public ClassFileBuilder attributes(Attribute attribute, Attribute... attributes);

281

282

/**

283

* Build the final ClassFile object

284

* @return Constructed ClassFile instance with all configured elements

285

*/

286

public ClassFile build();

287

}

288

```

289

290

**Usage Examples:**

291

292

```java

293

import aQute.bnd.classfile.builder.ClassFileBuilder;

294

import aQute.bnd.classfile.builder.MutableConstantPool;

295

import aQute.bnd.classfile.ClassFile;

296

import aQute.bnd.classfile.FieldInfo;

297

import aQute.bnd.classfile.MethodInfo;

298

299

// Build a simple public class

300

ClassFile simpleClass = new ClassFileBuilder(

301

ClassFile.ACC_PUBLIC, // access flags

302

61, // major version (Java 17)

303

0, // minor version

304

"com/example/GeneratedClass", // this class

305

"java/lang/Object" // super class

306

).build();

307

308

// Build class with interfaces and members

309

ClassFileBuilder builder = new ClassFileBuilder(

310

ClassFile.ACC_PUBLIC | ClassFile.ACC_FINAL,

311

61, 0,

312

"com/example/MyClass",

313

"java/lang/Object",

314

"java/io/Serializable", "java/lang/Cloneable"

315

);

316

317

// Add a private field

318

FieldInfo field = new FieldInfo(

319

ClassFile.ACC_PRIVATE,

320

"value",

321

"I", // int type descriptor

322

new Attribute[0]

323

);

324

builder.fields(field);

325

326

// Add a public constructor

327

MethodInfo constructor = new MethodInfo(

328

ClassFile.ACC_PUBLIC,

329

"<init>",

330

"()V", // void no-args constructor

331

new Attribute[0]

332

);

333

builder.methods(constructor);

334

335

ClassFile myClass = builder.build();

336

byte[] bytecode = myClass.write();

337

```

338

339

### ModuleInfoBuilder

340

341

Specialized builder for constructing module-info class files with complete module system support.

342

343

```java { .api }

344

/**

345

* Builder for constructing module-info ClassFile objects with module system features

346

*/

347

public class ModuleInfoBuilder extends ClassFileBuilder {

348

/**

349

* Create new ModuleInfoBuilder with default module-info structure

350

* Automatically sets ACC_MODULE flag, Java 9+ version, and adds java.base dependency

351

*/

352

public ModuleInfoBuilder();

353

354

// Module metadata

355

/**

356

* Get module name

357

* @return Module name string

358

*/

359

public String module_name();

360

361

/**

362

* Set module name

363

* @param module_name Module name

364

* @return This builder instance

365

*/

366

public ModuleInfoBuilder module_name(String module_name);

367

368

/**

369

* Get module version

370

* @return Module version string

371

*/

372

public String module_version();

373

374

/**

375

* Set module version

376

* @param module_version Module version string

377

* @return This builder instance

378

*/

379

public ModuleInfoBuilder module_version(String module_version);

380

381

/**

382

* Get module flags

383

* @return Module flags value

384

*/

385

public int module_flags();

386

387

/**

388

* Set module flags

389

* @param module_flags Module flags (ACC_OPEN, ACC_SYNTHETIC, ACC_MANDATED)

390

* @return This builder instance

391

*/

392

public ModuleInfoBuilder module_flags(int module_flags);

393

394

// Module dependencies (requires)

395

/**

396

* Get requires list

397

* @return Mutable list of ModuleAttribute.Require objects

398

*/

399

public List<ModuleAttribute.Require> requires();

400

401

/**

402

* Add module dependency without version

403

* @param moduleName Required module name

404

* @param flags Require flags (ACC_TRANSITIVE, ACC_STATIC_PHASE, etc.)

405

* @return This builder instance

406

*/

407

public ModuleInfoBuilder requires(String moduleName, int flags);

408

409

/**

410

* Add module dependency with version

411

* @param moduleName Required module name

412

* @param flags Require flags

413

* @param moduleVersion Required module version

414

* @return This builder instance

415

*/

416

public ModuleInfoBuilder requires(String moduleName, int flags, String moduleVersion);

417

418

// Package exports

419

/**

420

* Get exports list

421

* @return Mutable list of ModuleAttribute.Export objects

422

*/

423

public List<ModuleAttribute.Export> exports();

424

425

/**

426

* Export package to specific modules

427

* @param binaryPackageName Binary package name to export

428

* @param flags Export flags

429

* @param toModules Collection of target module names

430

* @return This builder instance

431

*/

432

public ModuleInfoBuilder exports(String binaryPackageName, int flags, Collection<String> toModules);

433

434

/**

435

* Export package unconditionally (to all modules)

436

* @param binaryPackageName Binary package name to export

437

* @param flags Export flags

438

* @return This builder instance

439

*/

440

public ModuleInfoBuilder exports(String binaryPackageName, int flags);

441

442

/**

443

* Export package to single module

444

* @param binaryPackageName Binary package name to export

445

* @param flags Export flags

446

* @param toModule Target module name

447

* @return This builder instance

448

*/

449

public ModuleInfoBuilder exports(String binaryPackageName, int flags, String toModule);

450

451

/**

452

* Export package to multiple modules

453

* @param binaryPackageName Binary package name to export

454

* @param flags Export flags

455

* @param toModules Target module names

456

* @return This builder instance

457

*/

458

public ModuleInfoBuilder exports(String binaryPackageName, int flags, String... toModules);

459

460

// Package opens (reflection access)

461

/**

462

* Get opens list

463

* @return Mutable list of ModuleAttribute.Open objects

464

*/

465

public List<ModuleAttribute.Open> opens();

466

467

/**

468

* Open package for reflection to specific modules

469

* @param binaryPackageName Binary package name to open

470

* @param flags Open flags

471

* @param toModules Collection of target module names

472

* @return This builder instance

473

*/

474

public ModuleInfoBuilder opens(String binaryPackageName, int flags, Collection<String> toModules);

475

476

/**

477

* Open package for reflection unconditionally

478

* @param binaryPackageName Binary package name to open

479

* @param flags Open flags

480

* @return This builder instance

481

*/

482

public ModuleInfoBuilder opens(String binaryPackageName, int flags);

483

484

/**

485

* Open package for reflection to single module

486

* @param binaryPackageName Binary package name to open

487

* @param flags Open flags

488

* @param toModule Target module name

489

* @return This builder instance

490

*/

491

public ModuleInfoBuilder opens(String binaryPackageName, int flags, String toModule);

492

493

/**

494

* Open package for reflection to multiple modules

495

* @param binaryPackageName Binary package name to open

496

* @param flags Open flags

497

* @param toModules Target module names

498

* @return This builder instance

499

*/

500

public ModuleInfoBuilder opens(String binaryPackageName, int flags, String... toModules);

501

502

// Service usage

503

/**

504

* Get uses list

505

* @return Mutable list of service interface names

506

*/

507

public List<String> uses();

508

509

/**

510

* Add service interface usage

511

* @param binaryClassName Service interface binary name

512

* @return This builder instance

513

*/

514

public ModuleInfoBuilder uses(String binaryClassName);

515

516

/**

517

* Add multiple service interface usages from collection

518

* @param binaryClassNames Collection of service interface binary names

519

* @return This builder instance

520

*/

521

public ModuleInfoBuilder uses(Collection<String> binaryClassNames);

522

523

/**

524

* Add multiple service interface usages from array

525

* @param binaryClassNames Array of service interface binary names

526

* @return This builder instance

527

*/

528

public ModuleInfoBuilder uses(String[] binaryClassNames);

529

530

/**

531

* Add multiple service interface usages

532

* @param binaryClassName First service interface binary name

533

* @param binaryClassNames Additional service interface binary names

534

* @return This builder instance

535

*/

536

public ModuleInfoBuilder uses(String binaryClassName, String... binaryClassNames);

537

538

// Service provision

539

/**

540

* Get provides list

541

* @return Mutable list of ModuleAttribute.Provide objects

542

*/

543

public List<ModuleAttribute.Provide> provides();

544

545

/**

546

* Add service implementation provision

547

* @param binaryClassName Service interface binary name

548

* @param binaryWithClassNames Collection of implementation class binary names

549

* @return This builder instance

550

*/

551

public ModuleInfoBuilder provides(String binaryClassName, Collection<String> binaryWithClassNames);

552

553

/**

554

* Add single service implementation provision

555

* @param binaryClassName Service interface binary name

556

* @param binaryWithClassName Implementation class binary name

557

* @return This builder instance

558

*/

559

public ModuleInfoBuilder provides(String binaryClassName, String binaryWithClassName);

560

561

/**

562

* Add multiple service implementation provisions

563

* @param binaryClassName Service interface binary name

564

* @param binaryWithClassNames Implementation class binary names

565

* @return This builder instance

566

*/

567

public ModuleInfoBuilder provides(String binaryClassName, String... binaryWithClassNames);

568

569

// Main class

570

/**

571

* Get main class

572

* @return Main class binary name

573

*/

574

public String mainClass();

575

576

/**

577

* Set main class for module

578

* @param binaryClassName Main class binary name

579

* @return This builder instance

580

*/

581

public ModuleInfoBuilder mainClass(String binaryClassName);

582

583

// Package listing

584

/**

585

* Get packages list

586

* @return Mutable list of package binary names

587

*/

588

public List<String> packages();

589

590

/**

591

* Add package to module

592

* @param binaryPackageName Package binary name

593

* @return This builder instance

594

*/

595

public ModuleInfoBuilder packages(String binaryPackageName);

596

597

/**

598

* Add multiple packages from collection

599

* @param binaryPackageNames Collection of package binary names

600

* @return This builder instance

601

*/

602

public ModuleInfoBuilder packages(Collection<String> binaryPackageNames);

603

604

/**

605

* Add multiple packages from array

606

* @param binaryPackageNames Array of package binary names

607

* @return This builder instance

608

*/

609

public ModuleInfoBuilder packages(String[] binaryPackageNames);

610

611

/**

612

* Add multiple packages

613

* @param binaryPackageName First package binary name

614

* @param binaryPackageNames Additional package binary names

615

* @return This builder instance

616

*/

617

public ModuleInfoBuilder packages(String binaryPackageName, String... binaryPackageNames);

618

619

/**

620

* Build module-info ClassFile with ModuleAttribute, ModulePackagesAttribute, and ModuleMainClassAttribute

621

* @return Constructed module-info ClassFile

622

*/

623

@Override

624

public ClassFile build();

625

}

626

```

627

628

**Usage Examples:**

629

630

```java

631

import aQute.bnd.classfile.builder.ModuleInfoBuilder;

632

import aQute.bnd.classfile.ModuleAttribute;

633

import aQute.bnd.classfile.ClassFile;

634

635

// Build a simple module

636

ModuleInfoBuilder moduleBuilder = new ModuleInfoBuilder()

637

.module_name("com.example.mymodule")

638

.module_version("1.0.0");

639

640

// Add dependencies

641

moduleBuilder

642

.requires("java.logging", 0) // standard dependency

643

.requires("java.desktop", ModuleAttribute.Require.ACC_TRANSITIVE); // transitive

644

645

// Export packages

646

moduleBuilder

647

.exports("com/example/api", 0) // public API

648

.exports("com/example/impl", 0, "com.friendly"); // qualified export

649

650

// Open packages for reflection

651

moduleBuilder

652

.opens("com/example/internal", 0, "com.test.framework");

653

654

// Service usage and provision

655

moduleBuilder

656

.uses("java/sql/Driver")

657

.provides("java/sql/Driver", "com/example/db/MyDriver");

658

659

// Set main class and build

660

ClassFile moduleInfo = moduleBuilder

661

.mainClass("com/example/Main")

662

.build();

663

664

byte[] moduleInfoBytes = moduleInfo.write();

665

```

666

667

### MutableConstantPool

668

669

Extensible constant pool implementation for building class files with automatic index management.

670

671

```java { .api }

672

/**

673

* Mutable constant pool for building class files with automatic entry management

674

*/

675

public class MutableConstantPool extends ConstantPool {

676

/**

677

* Create empty mutable constant pool

678

*/

679

public MutableConstantPool();

680

681

/**

682

* Create mutable constant pool copying from existing constant pool

683

* @param constantPool Existing ConstantPool to copy from

684

*/

685

public MutableConstantPool(ConstantPool constantPool);

686

687

/**

688

* Get constant pool size

689

* @return Number of entries in constant pool

690

*/

691

@Override

692

public int size();

693

694

/**

695

* Get entry at specified index

696

* @param index Entry index

697

* @return Constant pool entry object

698

*/

699

@Override

700

public <T> T entry(int index);

701

702

/**

703

* Set entry at specified index

704

* @param index Entry index

705

* @param entry Entry object to set

706

* @return Previous entry at index

707

*/

708

public <T> T entry(int index, Object entry);

709

}

710

```

711

712

**Usage Examples:**

713

714

```java

715

import aQute.bnd.classfile.builder.MutableConstantPool;

716

import aQute.bnd.classfile.ConstantPool;

717

718

// Create new mutable constant pool

719

MutableConstantPool mcp = new MutableConstantPool();

720

721

// The pool automatically manages UTF-8 strings, class references, etc.

722

// when used with ClassFileBuilder - entries are added as needed

723

724

// Copy existing constant pool for modification

725

ClassFile existing = ClassFile.parseClassFile(inputStream);

726

MutableConstantPool modified = new MutableConstantPool(existing.constant_pool);

727

728

// Use with ClassFileBuilder

729

ClassFileBuilder builder = new ClassFileBuilder(

730

ClassFile.ACC_PUBLIC, 61, 0,

731

"com/example/NewClass", "java/lang/Object"

732

);

733

builder.constant_pool(modified);

734

```

735

736

### ReflectBuilder

737

738

Utility for creating ClassFileBuilder instances from existing Java Class objects via reflection.

739

740

```java { .api }

741

/**

742

* Utility for building ClassFile objects from Java Class instances via reflection.

743

* Creates ClassFileBuilder instances populated with class metadata, fields, and methods.

744

* Note: Limited by Java reflection API - cannot access bytecode, local variables, etc.

745

*/

746

public class ReflectBuilder {

747

/**

748

* Create ClassFileBuilder from Java Class object

749

* Captures class metadata, declared fields, and declared methods using reflection

750

* @param c Class object to build from

751

* @return ClassFileBuilder initialized with class information

752

*/

753

public static ClassFileBuilder of(Class<?> c);

754

}

755

```

756

757

**Usage Examples:**

758

759

```java

760

import aQute.bnd.classfile.builder.ReflectBuilder;

761

import aQute.bnd.classfile.builder.ClassFileBuilder;

762

import aQute.bnd.classfile.ClassFile;

763

764

// Build ClassFile from existing Java class

765

Class<?> stringClass = String.class;

766

ClassFileBuilder builder = ReflectBuilder.of(stringClass);

767

768

// Modify the reflected class structure

769

builder.fields(new FieldInfo(

770

ClassFile.ACC_PRIVATE,

771

"customField",

772

"Ljava/lang/String;",

773

new Attribute[0]

774

));

775

776

// Build modified version

777

ClassFile modifiedString = builder.build();

778

byte[] bytecode = modifiedString.write();

779

780

// Useful for analysis and transformation of built-in classes

781

ClassFileBuilder listBuilder = ReflectBuilder.of(java.util.ArrayList.class);

782

System.out.println("ArrayList methods: " + listBuilder.methods().size());

783

```

784

785

## Constants

786

787

```java { .api }

788

// Module flags (for ModuleAttribute and ModuleInfoBuilder)

789

public class ModuleAttribute {

790

public static final int ACC_OPEN = 0x0020; // Open module

791

public static final int ACC_SYNTHETIC = 0x1000; // Synthetic module

792

public static final int ACC_MANDATED = 0x8000; // Mandated module

793

794

// Require flags

795

public static class Require {

796

public static final int ACC_TRANSITIVE = 0x0020; // Transitive dependency

797

public static final int ACC_STATIC_PHASE = 0x0040; // Static phase dependency

798

public static final int ACC_SYNTHETIC = 0x1000; // Synthetic requirement

799

public static final int ACC_MANDATED = 0x8000; // Mandated requirement

800

}

801

}

802

803

// Class access flags (inherited from ClassFile)

804

public class ClassFile {

805

public static final int ACC_PUBLIC = 0x0001; // Public class

806

public static final int ACC_FINAL = 0x0010; // Final class

807

public static final int ACC_SUPER = 0x0020; // Super class flag

808

public static final int ACC_INTERFACE = 0x0200; // Interface

809

public static final int ACC_ABSTRACT = 0x0400; // Abstract class

810

public static final int ACC_SYNTHETIC = 0x1000; // Synthetic class

811

public static final int ACC_ANNOTATION = 0x2000; // Annotation type

812

public static final int ACC_ENUM = 0x4000; // Enum type

813

public static final int ACC_MODULE = 0x8000; // Module class

814

}

815

```

816

817

## Type Definitions

818

819

```java { .api }

820

// Core class file types used by builders

821

public class ClassFile {

822

public final int minor_version;

823

public final int major_version;

824

public final ConstantPool constant_pool;

825

public final int access;

826

public final String this_class;

827

public final String super_class;

828

public final String[] interfaces;

829

public final FieldInfo[] fields;

830

public final MethodInfo[] methods;

831

public final Attribute[] attributes;

832

}

833

834

public class FieldInfo extends MemberInfo {

835

public FieldInfo(int access, String name, String descriptor, Attribute[] attributes);

836

}

837

838

public class MethodInfo extends MemberInfo {

839

public MethodInfo(int access, String name, String descriptor, Attribute[] attributes);

840

}

841

842

public abstract class MemberInfo extends ElementInfo {

843

public final String name;

844

public final String descriptor;

845

}

846

847

public abstract class ElementInfo {

848

public final int access;

849

public final Attribute[] attributes;

850

}

851

852

public interface Attribute {

853

String name();

854

void write(DataOutput out, ConstantPool constant_pool) throws IOException;

855

int attribute_length();

856

}

857

858

// Module-specific attribute types

859

public class ModuleAttribute implements Attribute {

860

public final String module_name;

861

public final int module_flags;

862

public final String module_version;

863

public final Require[] requires;

864

public final Export[] exports;

865

public final Open[] opens;

866

public final String[] uses;

867

public final Provide[] provides;

868

869

public static class Require {

870

public final String requires;

871

public final int requires_flags;

872

public final String requires_version;

873

}

874

875

public static class Export {

876

public final String exports;

877

public final int exports_flags;

878

public final String[] exports_to;

879

}

880

881

public static class Open {

882

public final String opens;

883

public final int opens_flags;

884

public final String[] opens_to;

885

}

886

887

public static class Provide {

888

public final String provides;

889

public final String[] provides_with;

890

}

891

}

892

893

public class ModuleMainClassAttribute implements Attribute {

894

public final String main_class;

895

}

896

897

public class ModulePackagesAttribute implements Attribute {

898

public final String[] packages;

899

}

900

```