private void restoreAndRemoveTransformedClasses( @Nonnull Set<ClassIdentification> classesToRestore) { RedefinitionEngine redefinitionEngine = new RedefinitionEngine(); for (ClassIdentification transformedClassId : classesToRestore) { byte[] definitionToRestore = transformedClasses.get(transformedClassId); redefinitionEngine.restoreToDefinition( transformedClassId.getLoadedClass(), definitionToRestore); } transformedClasses.keySet().removeAll(classesToRestore); }
void removeMockedClasses(@Nonnull List<Class<?>> previousMockedClasses) { int currentMockedClassCount = mockedClasses.size(); if (currentMockedClassCount > 0) { int previousMockedClassCount = previousMockedClasses.size(); if (previousMockedClassCount == 0) { mockedClasses.clear(); mockedTypesAndInstances.clear(); } else if (previousMockedClassCount < currentMockedClassCount) { mockedClasses.retainAll(previousMockedClasses); mockedTypesAndInstances.keySet().retainAll(previousMockedClasses); } } }
void restoreTransformedClasses(@Nonnull Set<ClassIdentification> previousTransformedClasses) { if (!transformedClasses.isEmpty()) { Set<ClassIdentification> classesToRestore; if (previousTransformedClasses.isEmpty()) { classesToRestore = transformedClasses.keySet(); } else { classesToRestore = getTransformedClasses(); classesToRestore.removeAll(previousTransformedClasses); } if (!classesToRestore.isEmpty()) { restoreAndRemoveTransformedClasses(classesToRestore); } } }
@Nonnull Set<ClassIdentification> getTransformedClasses() { return transformedClasses.isEmpty() ? Collections.<ClassIdentification>emptySet() : new HashSet<ClassIdentification>(transformedClasses.keySet()); }