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

39
LINES

< > BotCompany Repo | #1004056 // BCEL - change source file name within .class - seems to work

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

Uses 1311K of libraries. Click here for Pure Java version (493L/4K/12K).

1  
!759
2  
3  
lib 1004055
4  
5  
import org.apache.bcel.classfile.ClassParser;
6  
import org.apache.bcel.classfile.JavaClass;
7  
import org.apache.bcel.classfile.Attribute;
8  
import org.apache.bcel.classfile.SourceFile;
9  
import org.apache.bcel.generic.*;
10  
11  
p {
12  
  JavaClass c = new ClassParser (
13  
main.class.getResourceAsStream("/main.class"), "main.class").parse();
14  
  print(c.getSourceFileName());
15  
  
16  
  ClassGen g = new ClassGen(c);
17  
  
18  
  S newName = parseSnippetID(programID()) + ".javax";
19  
  int nameIndex = g.getConstantPool().addUtf8(newName);
20  
  
21  
  for (Attribute attr : g.getAttributes())
22  
    if (attr instanceof SourceFile) {
23  
      g.removeAttribute(attr);
24  
      break;
25  
    }
26  
    
27  
  g.addAttribute(new SourceFile(
28  
    g.getConstantPool().addUtf8("SourceFile"), 
29  
    2,
30  
    nameIndex,
31  
    g.getConstantPool().getConstantPool()));
32  
      
33  
  c = g.getJavaClass();
34  
  File f;
35  
  c.dump(f = prepareProgramFile("main.class"));
36  
37  
  c = new ClassParser (f.getPath()).parse();
38  
  print(c.getSourceFileName());
39  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004056
Snippet name: BCEL - change source file name within .class - seems to work
Eternal ID of this version: #1004056/1
Text MD5: b7e725761c703f2aa58b958e25979c49
Transpilation MD5: e47f417a70051c3b8154d668a45b4110
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-05 14:38:02
Source code size: 1014 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 629 / 675
Referenced in: [show references]