diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/DynamicType.java b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/DynamicType.java index 319c99a7f0..3455a4d879 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/DynamicType.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/DynamicType.java @@ -86,6 +86,13 @@ public interface DynamicType extends ClassFileLocator { */ byte[] getBytes(); + /** + * Returns a set of all types that are represented by this dynamic type. + * + * @return A set of all represented types. + */ + Set getTypeDescriptions(); + /** *

* Returns a map of all auxiliary types that are required for making use of the main type. @@ -6123,6 +6130,18 @@ public void close() { /* do nothing */ } + /** + * {@inheritDoc} + */ + public Set getTypeDescriptions() { + Set types = new LinkedHashSet(); + types.add(typeDescription); + for (DynamicType auxiliaryType : auxiliaryTypes) { + types.addAll(auxiliaryType.getTypeDescriptions()); + } + return types; + } + /** * {@inheritDoc} */ diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ClassInjector.java b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ClassInjector.java index a98e0d6eef..26c6c78194 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ClassInjector.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ClassInjector.java @@ -97,6 +97,8 @@ public interface ClassInjector { */ Map> inject(Set names, ClassFileLocator classFileLocator); + Map> inject(List dynamicTypes); + /** * Injects the given types into the represented class loader. * @@ -118,6 +120,23 @@ public interface ClassInjector { */ abstract class AbstractBase implements ClassInjector { + /** + * {@inheritDoc} + */ + public Map> inject(List dynamicTypes) { + Map types = new LinkedHashMap(); + for (DynamicType dynamicType : dynamicTypes) { + for (TypeDescription typeDescription : dynamicType.getTypeDescriptions()) { + types.put(typeDescription.getName(), typeDescription); + } + } + Map> result = new HashMap>(); + for (Map.Entry> entry : inject(types.keySet(), new ClassFileLocator.Compound(dynamicTypes)).entrySet()) { + result.put(types.get(entry.getKey()), entry.getValue()); + } + return result; + } + /** * {@inheritDoc} */ @@ -127,7 +146,7 @@ public Map> inject(Map> loadedTypes = injectRaw(binaryRepresentations); - Map> result = new LinkedHashMap>(); + Map> result = new HashMap>(); for (TypeDescription typeDescription : types.keySet()) { result.put(typeDescription, loadedTypes.get(typeDescription.getName())); }