Class BytecodeExtractor
java.lang.Object
io.github.mkoncek.classpathless.util.BytecodeExtractor
A utility class to extract useful information from class files, for example
type names, methods, fields.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
private static class
private static class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
static Collection
<String> extractDependencies
(IdentifiedBytecode initialClass, ClassesProvider classesProvider) This method returns all the class names that are required for the compilation of a source file corresponding to the bytecode of initialClass.(package private) static Collection
<String> extractDependenciesImpl
(IdentifiedBytecode initialClass, ClassesProvider classesProvider, Consumer<String> first, Consumer<String> second, Consumer<String> third) This is an implementation method.private static void
extractDescriptor
(String descriptor, Collection<String> result) Function for extracting the type names from descriptors.extractDirectNestedClasses
(byte[] classFile) Extracts all directly nested class names from the initial outer class.extractDirectNestedClassesFrom
(byte[] classFile) static Collection
<String> extractFields
(byte[] classFile) Extracts all the field names of the provided class excluding inherited fields.extractFullClassGroup
(byte[] classFile, ClassesProvider classesProvider) Walk up to outermost class and return all its transitively nested classes.static Collection
<String> extractInterfaces
(byte[] classFile) Extracts the names of all directly implemented interfaces, i.static Collection
<String> extractMethods
(byte[] classFile) Extracts all method names of given class.extractNestedClasses
(byte[] classFile, ClassesProvider classesProvider) Recursively extracts all the nested class names from the initial outer class possibly by pulling more class files from the class provider.extractNestedClassesFrom
(byte[] classFile, ClassesProvider classesProvider) extractOuterClass
(byte[] classFile) Extracts the name of the outer class of the provided class.private static void
extractSignature
(String signature, Collection<String> result) Function for extracting the contents of formal parameters, i.extractSuperClass
(byte[] classFile) Extracts the name of the super class of the provided class.extractTypenames
(byte[] classFile) Extracts all type names present in the .class file.extractTypenamesFrom
(byte[] classFile)
-
Field Details
-
CURRENT_ASM_OPCODE
private static final int CURRENT_ASM_OPCODE- See Also:
-
FORMAL_CONTENTS_PATTERN
-
classes
-
-
Constructor Details
-
BytecodeExtractor
public BytecodeExtractor()
-
-
Method Details
-
dot
-
extractDescriptor
Function for extracting the type names from descriptors. -
extractSignature
Function for extracting the contents of formal parameters, i. e. those contained in invalid input: '<'> parentheses. This function does not do full signature parsing, just a simple search. The types not caught by the regular expression should be already caught by other visitors. For reference about signatures, see: https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.3 -
extractTypenamesFrom
-
extractDirectNestedClassesFrom
-
extractNestedClassesFrom
private SortedSet<String> extractNestedClassesFrom(byte[] classFile, ClassesProvider classesProvider) -
extractTypenames
Extracts all type names present in the .class file.- Parameters:
classFile
- The file to extract names from.- Returns:
- The set of fully qualified type names present in the class file.
-
extractFields
Extracts all the field names of the provided class excluding inherited fields.- Parameters:
classFile
- The file to extract names from.- Returns:
- The collection of field names.
-
extractMethods
Extracts all method names of given class. This will not include methods of inner classes nor inherited methods (unless they are overriden).- Parameters:
classFile
- The file to extract names from.- Returns:
- The collection of method names.
-
extractInterfaces
Extracts the names of all directly implemented interfaces, i. e. not transitively.- Parameters:
classFile
- The file to extract names from.- Returns:
- The collection of implemented interfaces.
-
extractSuperClass
Extracts the name of the super class of the provided class. Classes which to not inherit this will be equal to "java.lang.Object".- Parameters:
classFile
- The file to extract the name from.- Returns:
- The name of the super class.
-
extractOuterClass
Extracts the name of the outer class of the provided class.- Parameters:
classFile
- The file to extract the name from.- Returns:
- The name of the super class.
-
extractDirectNestedClasses
Extracts all directly nested class names from the initial outer class.- Parameters:
classFile
- The file to extract names from.- Returns:
- The set of all directly nested fully qualified class names excluding the initial outer class.
-
extractNestedClasses
public static SortedSet<String> extractNestedClasses(byte[] classFile, ClassesProvider classesProvider) Recursively extracts all the nested class names from the initial outer class possibly by pulling more class files from the class provider.- Parameters:
classFile
- The file to extract names from.classesProvider
- The provider of nested classes' bytecode.- Returns:
- The set of all nested fully qualified class names excluding the initial outer class.
-
extractFullClassGroup
public static SortedSet<String> extractFullClassGroup(byte[] classFile, ClassesProvider classesProvider) Walk up to outermost class and return all its transitively nested classes.- Parameters:
classFile
- The file to extract names from.classesProvider
- The provider of nested classes' bytecode.- Returns:
- The set of all fully qualified class names of the nest to which this class belongs.
-
extractDependencies
public static Collection<String> extractDependencies(IdentifiedBytecode initialClass, ClassesProvider classesProvider) This method returns all the class names that are required for the compilation of a source file corresponding to the bytecode of initialClass.- Parameters:
initialClass
- The bytecode the dependencies of which are requested.classesProvider
- ClassesProvider of class dependencies.- Returns:
- A collection of all class names that are required for compilation.
-
extractDependenciesImpl
static Collection<String> extractDependenciesImpl(IdentifiedBytecode initialClass, ClassesProvider classesProvider, Consumer<String> first, Consumer<String> second, Consumer<String> third) This is an implementation method.- Parameters:
initialClass
- The bytecode the dependencies of which are requested.classesProvider
- ClassesProvider of class dependencies.first
- The consumer of a class name in case a class is added in the first phase.second
- The consumer of a class name in case a class is added in the second phase.third
- The consumer of a class name in case a class is added in the third phase.- Returns:
- A collection of all class names that are required for compilation.
-