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

29
LINES

< > BotCompany Repo | #1004069 // renameSourceInfoInClassFile

JavaX fragment (include)

1  
!include once #1019934 // BCEL
2  
3  
import org.apache.bcel.classfile.Attribute;
4  
import org.apache.bcel.classfile.SourceFile;
5  
import org.apache.bcel.generic.*;
6  
7  
static void renameSourceInfoInClassFile(File classFile, S newName) {
8  
  JavaClass c = new ClassParser(classFile.getPath(), classFile.getName()).parse();
9  
  //print(c.getSourceFileName());
10  
  
11  
  ClassGen g = new ClassGen(c);
12  
  
13  
  int nameIndex = g.getConstantPool().addUtf8(newName);
14  
  
15  
  for (Attribute attr : g.getAttributes())
16  
    if (attr instanceof SourceFile) {
17  
      g.removeAttribute(attr);
18  
      break;
19  
    }
20  
    
21  
  g.addAttribute(new SourceFile(
22  
    g.getConstantPool().addUtf8("SourceFile"), 
23  
    2,
24  
    nameIndex,
25  
    g.getConstantPool().getConstantPool()));
26  
      
27  
  c = g.getJavaClass();
28  
  c.dump(classFile); // overwrite!
29  
}

Author comment

Began life as a copy of #1004056

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004069
Snippet name: renameSourceInfoInClassFile
Eternal ID of this version: #1004069/2
Text MD5: 2a98ec057555a5584720cba5359563f3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-01 15:52:34
Source code size: 818 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 498 / 531
Version history: 1 change(s)
Referenced in: [show references]