Class ClassHierarchy
ClasFile coding utility: ClassHierarchy.
Mail from: Adam Sotona adam.sotona@oracle.com on Apr 28, 2024.
Your compiler reached the complexity where you reference generated classes from other generated classes. Class-File API in certain circumstances needs to know some information about the classes referenced from the generated bytecode. Such information is provided in ClassHierarchyInfo using functional interface ClassHierarchyResolver. By default is the information obtained from system class loader. However, the classes you generate are probably not yet known to the system class loader.
You should specify a custom ClassHierarchyResolver for your compiler as a
Class-File API option
ClassFile.of(ClassFile.ClassHierarchyResolverOption.of(...))
.
Here you have multiple options how to provide the missing information using combinations of ClassHierarchyResolver factory methods and custom code:
For example, if the required classes have been already generated and you can provide a physical access to them, you can compose the ClassHierarchyResolver this way:
ClassHierarchyResolver.defaultResolver().orElse(ClassHierarchyResolver. ofResourceParsing(Function<ClassDesc, InputStream>).cached())
Or if you know all the generated classes in advance, you can provide the missing info about the generated classes in a set and map form:
ClassHierarchyResolver.defaultResolver().orElse(ClassHierarchyResolver. of(Collection<ClassDesc> interfaces, Map<ClassDesc, ClassDesc> classToSuperClass))
Or in a form of dynamic direct implementation of the ClassHierarchyResolver:
ClassHierarchyResolver.defaultResolver().orElse(classDesc -> isInterface ? : ClassHierarchyInfo.ofInterface() : ClassHierarchyInfo.ofClass(ClassDesc superClass))
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Vector
<ClassHierarchy.Node> list of all Nodes.The classToSuperClass Map.private static Collection
<ClassDesc> The interfaces.private static final String
Marker in the AttributeOutputStream. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addClassToSuperClass
(ClassDesc cld, ClassDesc sup) Add a class to the classToSuperClass map.static ClassDesc
getClassDesc
(String classID) Returns the resulting ClassDesc.static String
getRealPrefix
(String sub) Get real prefix.static ClassDesc
getRealSuper
(ClassDesc sub) Get real super class.static ClassHierarchyResolver
get the ClassHierarchyResolver.static void
init()
Initiale local variables.static void
list()
Debug utility: list classToSuperClass map.private static ClassHierarchy.Node
Debug utility: Lookup a node.static void
print()
Debug utility: print classToSuperClass map etc.static void
Read a ClassHierarchy object.static void
Write a ClassHierarchy object to a AttributeOutputStream.
-
Field Details
-
classToSuperClass
-
interfaces
The interfaces. -
allNodes
list of all Nodes. -
mark
-
-
Constructor Details
-
ClassHierarchy
private ClassHierarchy()Default Constructor: NOT USED
-
-
Method Details
-
init
public static void init()Initiale local variables. -
getResolver
get the ClassHierarchyResolver.- Returns:
- the ClassHierarchyResolver.
-
addClassToSuperClass
-
getRealSuper
-
getRealPrefix
-
getClassDesc
-
list
public static void list()Debug utility: list classToSuperClass map. -
print
public static void print()Debug utility: print classToSuperClass map etc. -
lookup
Debug utility: Lookup a node.- Parameters:
name
- node's name.- Returns:
- the node.
-
writeObject
Write a ClassHierarchy object to a AttributeOutputStream.- Parameters:
oupt
- the AttributeOutputStream to write to.- Throws:
IOException
- if something went wrong.
-
readObject
Read a ClassHierarchy object.- Parameters:
inpt
- the AttributeInputStream to read from- Throws:
IOException
- if something went wrong.
-