Ejemplo n.º 1
0
  void restoreRedefinedClasses(@Nonnull Map<?, byte[]> previousDefinitions) {
    if (redefinedClasses.isEmpty()) {
      return;
    }

    RedefinitionEngine redefinitionEngine = new RedefinitionEngine();
    Iterator<Entry<Class<?>, byte[]>> itr = redefinedClasses.entrySet().iterator();

    while (itr.hasNext()) {
      Entry<Class<?>, byte[]> entry = itr.next();
      Class<?> redefinedClass = entry.getKey();
      byte[] currentDefinition = entry.getValue();
      byte[] previousDefinition = previousDefinitions.get(redefinedClass);

      //noinspection ArrayEquality
      if (currentDefinition != previousDefinition) {
        redefinitionEngine.restoreDefinition(redefinedClass, previousDefinition);

        if (previousDefinition == null) {
          restoreDefinition(redefinedClass);
          discardStateForCorrespondingMockClassIfAny(redefinedClass);
          itr.remove();
        } else {
          entry.setValue(previousDefinition);
        }
      }
    }
  }
Ejemplo n.º 2
0
  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);
  }
Ejemplo n.º 3
0
  public void restoreAndRemoveRedefinedClasses(@Nullable Set<Class<?>> desiredClasses) {
    Set<Class<?>> classesToRestore =
        desiredClasses == null ? redefinedClasses.keySet() : desiredClasses;
    RedefinitionEngine redefinitionEngine = new RedefinitionEngine();

    for (Class<?> redefinedClass : classesToRestore) {
      redefinitionEngine.restoreOriginalDefinition(redefinedClass);
      restoreDefinition(redefinedClass);
      discardStateForCorrespondingMockClassIfAny(redefinedClass);
    }

    if (desiredClasses == null) {
      redefinedClasses.clear();
    } else {
      redefinedClasses.keySet().removeAll(desiredClasses);
    }
  }