1 16 package net.sf.cglib.core; 17 18 import org.objectweb.asm.ClassAdapter; 19 import org.objectweb.asm.ClassReader; 20 import java.util.*; 21 22 public class ClassNameReader { 24 private ClassNameReader() { 25 } 26 27 private static final EarlyExitException EARLY_EXIT = new EarlyExitException(); 28 private static class EarlyExitException extends RuntimeException { } 29 30 public static String getClassName(ClassReader r) { 31 32 return getClassInfo(r)[0]; 33 34 } 35 36 public static String [] getClassInfo(ClassReader r) { 37 final List array = new ArrayList(); 38 try { 39 r.accept(new ClassAdapter(null) { 40 public void visit(int version, 41 int access, 42 String name, 43 String signature, 44 String superName, 45 String [] interfaces) { 46 array.add( name.replace('/', '.') ); 47 if(superName != null){ 48 array.add( superName.replace('/', '.') ); 49 } 50 for(int i = 0; i < interfaces.length; i++ ){ 51 array.add( interfaces[i].replace('/', '.') ); 52 } 53 54 throw EARLY_EXIT; 55 } 56 }, true); 57 } catch (EarlyExitException e) { } 58 59 return (String [])array.toArray( new String []{} ); 60 } 61 } 62 | Popular Tags |