Package com.tonic.parser
Class ClassPool
- java.lang.Object
-
- com.tonic.parser.ClassPool
-
public class ClassPool extends Object
A pool of parsed ClassFile objects, stored and retrieved by internal name.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassFilecreateNewClass(String className, int accessFlags)Creates new empty class with specified name and access flags.ClassFileget(String internalName)Retrieves ClassFile by internal name.List<ClassFile>getClasses()static ClassPoolgetDefault()Returns the shared default pool, lazily created with the JDK's classes loaded.ClassFileloadClass(byte[] classData)Loads class from byte array.ClassFileloadClass(InputStream is)Loads class from InputStream.voidloadJar(JarFile jar)Loads all .class files from JAR into pool.ClassFileloadPlatformClass(String clazz)Loads class from platform class loader.ClassFileloadSystemClass(String clazz)Loads class from system class loader.voidput(ClassFile classFile)Adds a ClassFile to the pool.booleanremove(String internalName)Removes a ClassFile from the pool by internal name.
-
-
-
Constructor Detail
-
ClassPool
public ClassPool() throws IOExceptionCreates a pool preloaded with the JDK's built-in classes (from the jrt image or rt.jar).- Throws:
IOException- if reading the JDK class files fails
-
ClassPool
public ClassPool(boolean empty)
Creates empty pool without loading built-in classes.- Parameters:
empty- ignored parameter to differentiate from default constructor
-
-
Method Detail
-
getDefault
public static ClassPool getDefault()
Returns the shared default pool, lazily created with the JDK's classes loaded.- Returns:
- the default ClassPool
-
put
public void put(ClassFile classFile)
Adds a ClassFile to the pool.- Parameters:
classFile- ClassFile to add
-
remove
public boolean remove(String internalName)
Removes a ClassFile from the pool by internal name.- Parameters:
internalName- internal name (e.g., "java/lang/Object")- Returns:
- true if a class was removed, false otherwise
-
get
public ClassFile get(String internalName)
Retrieves ClassFile by internal name.- Parameters:
internalName- internal name (e.g., "java/lang/Object")- Returns:
- ClassFile if found, null otherwise
-
loadClass
public ClassFile loadClass(byte[] classData)
Loads class from byte array.- Parameters:
classData- complete .class file bytes- Returns:
- loaded ClassFile
-
loadClass
public ClassFile loadClass(InputStream is) throws IOException
Loads class from InputStream.- Parameters:
is- InputStream containing .class file- Returns:
- loaded ClassFile
- Throws:
IOException- if reading or parsing fails
-
loadSystemClass
public ClassFile loadSystemClass(String clazz) throws IOException
Loads class from system class loader.- Parameters:
clazz- internal class name (e.g., "java/lang/Object")- Returns:
- loaded ClassFile
- Throws:
IOException- if loading fails
-
loadPlatformClass
public ClassFile loadPlatformClass(String clazz) throws IOException
Loads class from platform class loader.- Parameters:
clazz- internal class name (e.g., "java/lang/Object")- Returns:
- loaded ClassFile
- Throws:
IOException- if loading fails
-
loadJar
public void loadJar(JarFile jar) throws IOException
Loads all .class files from JAR into pool.- Parameters:
jar- JarFile to read- Throws:
IOException- if reading fails
-
createNewClass
public ClassFile createNewClass(String className, int accessFlags) throws IOException
Creates new empty class with specified name and access flags.- Parameters:
className- internal class name (e.g., "com/tonic/NewClass")accessFlags- access flags for the class- Returns:
- newly created ClassFile
- Throws:
IOException- if rebuilding failsIllegalArgumentException- if name invalid or class exists
-
-