Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

39
LINES

< > BotCompany Repo | #1034315 // Test making class implementing interface from scratch with BCEL using ClassMaker + MethodMaker [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 1311K of libraries. Click here for Pure Java version (9648L/46K).

1  
!7
2  
3  
set flag AllPublic.
4  
5  
p {
6  
  ClassMaker<IF0> c = new(IF0);
7  
  
8  
  // make code for get() method
9  
  
10  
  var m = new MethodMaker(c.cg, O, "get");
11  
  
12  
  // declare and create StringBuffer
13  
  
14  
  int buffer = m.newLocalVar();
15  
  m.newObject(StringBuffer.class).astore(buffer);
16  
  
17  
  // Append two strings
18  
  
19  
  for (string : ll("Hello ", "world")) {
20  
    m.aload(buffer).stringConstant(string);
21  
    m.il.append(m.factory.createAppend(org.apache.bcel.generic.Type.OBJECT));
22  
  }
23  
  
24  
  // call StringBuffer.toString() and return
25  
  
26  
  m.aload(buffer);
27  
  m.invokeVirtual(StringBuffer.class, S, "toString");
28  
  m.areturn().done();
29  
  
30  
  // disassemble because it looks cool
31  
  
32  
  c.printClassWithMethods();
33  
  
34  
  // bake class, load & create instance
35  
  
36  
  IF0 f = c.newInstance();
37  
  print(f);
38  
  assertEqualsVerbose("Hello world", f!);
39  
}

Author comment

Began life as a copy of #1034311

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034315
Snippet name: Test making class implementing interface from scratch with BCEL using ClassMaker + MethodMaker [OK]
Eternal ID of this version: #1034315/4
Text MD5: 94051bcb8c7120cfe0e9da46447e39d4
Transpilation MD5: 26fb1cd25b3db54e9b03ddcb1b91bb09
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-01 20:58:33
Source code size: 850 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 218 / 817
Version history: 3 change(s)
Referenced in: [show references]