33 * SPDX-License-Identifier: GPL-2.0-only */
44package de .uka .ilkd .key .proof .replay ;
55
6+ import java .lang .reflect .Field ;
67import java .nio .file .Files ;
78import java .nio .file .Path ;
9+ import java .util .HashMap ;
810import java .util .HashSet ;
911
1012import de .uka .ilkd .key .control .KeYEnvironment ;
13+ import de .uka .ilkd .key .proof .Counter ;
1114import de .uka .ilkd .key .proof .Proof ;
1215import de .uka .ilkd .key .settings .GeneralSettings ;
1316
2730class TestCopyingReplayer {
2831 public static final Path testCaseDirectory = FindResources .getTestCasesDirectory ();
2932
33+ /**
34+ * Reset all counters associated with this service.
35+ * Only use this method if the proof is empty!
36+ */
37+ public void resetCounters (Proof proof ) {
38+ if (proof .root ().childrenCount () > 0 ) {
39+ throw new IllegalStateException ("tried to reset counters on non-empty proof" );
40+ }
41+
42+ try {
43+ final Field countersField = proof .getServices ().getClass ().getDeclaredField ("counters" );
44+ countersField .setAccessible (true );
45+ // noinspection unchecked
46+ ((HashMap <String , Counter >) countersField .get (proof .getServices ())).clear ();
47+ } catch (NoSuchFieldException | IllegalAccessException e ) {
48+ throw new RuntimeException (e );
49+ }
50+ }
51+
3052 @ Test
3153 void testJavaProof () throws Exception {
3254 GeneralSettings .noPruningClosed = false ;
@@ -48,7 +70,7 @@ void testJavaProof() throws Exception {
4870
4971 // clear proof2, replay proof1 on top
5072 proof2 .pruneProof (proof2 .root ());
51- proof2 . getServices (). resetCounters ();
73+ resetCounters (proof2 );
5274 new CopyingProofReplayer (proof1 , proof2 ).copy (proof1 .root (),
5375 proof2 .getOpenGoal (proof2 .root ()), new HashSet <>());
5476
0 commit comments