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

22
LINES

< > BotCompany Repo | #1031552 // byteCodePathForClass - use getBytecodePathForClass instead

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4624L/26K).

// finds the byte code path root (dir or jar)
// TODO: inner classes will not be found (need to replace . with $)
static File byteCodePathForClass(Class c) {
  if (c == null) null;
  ClassLoader cl = getClassLoader(c);
  
  // handle JavaXClassLoader
  Cl<File> files = cast getOpt(cl, 'files);
  if (files != null) {
    S name = c.getName().replace('.', '/') + ".class";
    for (File location : files) 
      if (dirOrZipContainsPath(location, name))
        ret location;
    fail(name + " not found in: " + files);
  }
  
  null;
}

static File byteCodePathForClass(O o) {
  ret byteCodePathForClass(_getClass(o));
}

Author comment

Began life as a copy of #1012231

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031552
Snippet name: byteCodePathForClass - use getBytecodePathForClass instead
Eternal ID of this version: #1031552/7
Text MD5: 63389302febcf02684124418b353a703
Transpilation MD5: 47f2dca5a596ededcc6b459a0767fab9
Author: stefan
Category: javax / byte code
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-21 17:20:38
Source code size: 642 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 88 / 146
Version history: 6 change(s)
Referenced in: [show references]