Skip to content

Commit

Permalink
Add methods that allow that loading is avoided.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Oct 31, 2024
1 parent 5a45f35 commit d16aee4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,19 @@ public interface DynamicType extends ClassFileLocator {
*/
byte[] getBytes();

/**
* Returns a set of all auxiliary types that are represented by this dynamic type.
*
* @return A set of all auxiliary types.
*/
Set<TypeDescription> getAuxiliaryTypeDescriptions();

/**
* Returns a set of all types that are represented by this dynamic type.
*
* @return A set of all represented types.
*/
Set<TypeDescription> getTypeDescriptions();
Set<TypeDescription> getAllTypeDescriptions();

/**
* <p>
Expand Down Expand Up @@ -6133,11 +6140,22 @@ public void close() {
/**
* {@inheritDoc}
*/
public Set<TypeDescription> getTypeDescriptions() {
public Set<TypeDescription> getAuxiliaryTypeDescriptions() {
Set<TypeDescription> types = new LinkedHashSet<TypeDescription>();
for (DynamicType auxiliaryType : auxiliaryTypes) {
types.addAll(auxiliaryType.getAllTypeDescriptions());
}
return types;
}

/**
* {@inheritDoc}
*/
public Set<TypeDescription> getAllTypeDescriptions() {
Set<TypeDescription> types = new LinkedHashSet<TypeDescription>();
types.add(typeDescription);
for (DynamicType auxiliaryType : auxiliaryTypes) {
types.addAll(auxiliaryType.getTypeDescriptions());
types.addAll(auxiliaryType.getAllTypeDescriptions());
}
return types;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ public interface ClassInjector {
*/
Map<String, Class<?>> inject(Set<String> names, ClassFileLocator classFileLocator);

Map<TypeDescription, Class<?>> inject(List<? extends DynamicType> dynamicTypes);

/**
* Injects the given types into the represented class loader.
*
Expand All @@ -120,23 +118,6 @@ public interface ClassInjector {
*/
abstract class AbstractBase implements ClassInjector {

/**
* {@inheritDoc}
*/
public Map<TypeDescription, Class<?>> inject(List<? extends DynamicType> dynamicTypes) {
Map<String, TypeDescription> types = new LinkedHashMap<String, TypeDescription>();
for (DynamicType dynamicType : dynamicTypes) {
for (TypeDescription typeDescription : dynamicType.getTypeDescriptions()) {
types.put(typeDescription.getName(), typeDescription);
}
}
Map<TypeDescription, Class<?>> result = new HashMap<TypeDescription, Class<?>>();
for (Map.Entry<String, Class<?>> entry : inject(types.keySet(), new ClassFileLocator.Compound(dynamicTypes)).entrySet()) {
result.put(types.get(entry.getKey()), entry.getValue());
}
return result;
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,24 @@ public void testIterationOrder() throws Exception {
assertThat(types.hasNext(), is(false));
}

@Test
public void testIterationOrderAllDescriptions() throws Exception {
Iterator<TypeDescription> types = dynamicType.getAllTypeDescriptions().iterator();
assertThat(types.hasNext(), is(true));
assertThat(types.next(), is(typeDescription));
assertThat(types.hasNext(), is(true));
assertThat(types.next(), is(auxiliaryTypeDescription));
assertThat(types.hasNext(), is(false));
}

@Test
public void testIterationOrderAuxiliaryDescriptions() throws Exception {
Iterator<TypeDescription> types = dynamicType.getAuxiliaryTypeDescriptions().iterator();
assertThat(types.hasNext(), is(true));
assertThat(types.next(), is(auxiliaryTypeDescription));
assertThat(types.hasNext(), is(false));
}

@Test
public void testClassFileLocator() throws Exception {
assertThat(dynamicType.locate(FOOBAR.replace('/', '.')).isResolved(), is(true));
Expand Down

0 comments on commit d16aee4

Please sign in to comment.