Skip to content

Commit

Permalink
Fix program element printing in proof saver (#3073)
Browse files Browse the repository at this point in the history
See #3071. This PR changes the saver to use a new printer method that
omits the final `;`. Probably the behaviour was inadvertantly modified
in #3034.
  • Loading branch information
WolframPfeifer committed Mar 17, 2023
2 parents 6cbbe4e + bae42dd commit 74abc6a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
13 changes: 13 additions & 0 deletions key.core/src/main/java/de/uka/ilkd/key/pp/PrettyPrinter.java
Expand Up @@ -87,6 +87,19 @@ public void print(SourceElement e) {
l.end();
}

/**
* Alternative entry method for this class. Omits the trailing semicolon in the output.
*
* @param s source element to print
*/
public void printFragment(SourceElement s) {
l.beginRelativeC(0);
markStart(s);
s.visit(this);
markEnd(s);
l.end();
}

/**
* Marks the start of the first executable statement ...
*
Expand Down
Expand Up @@ -739,7 +739,7 @@ public static String escapeCharacters(String toEscape) {

public static String printProgramElement(ProgramElement pe) {
PrettyPrinter printer = PrettyPrinter.purePrinter();
printer.print(pe);
printer.printFragment(pe);
return printer.result();
}

Expand Down
20 changes: 20 additions & 0 deletions key.core/src/test/java/de/uka/ilkd/key/pp/PrettyPrinterTest.java
@@ -0,0 +1,20 @@
package de.uka.ilkd.key.pp;

import de.uka.ilkd.key.java.abstraction.KeYJavaType;
import de.uka.ilkd.key.logic.ProgramElementName;
import de.uka.ilkd.key.logic.op.LocationVariable;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class PrettyPrinterTest {
@Test
void printLocationVariable() {
// Test that the pretty printer does not add a ';' when using printFragment.
// This is important for saving instantiations (see #3071)
PrettyPrinter pp = PrettyPrinter.purePrinter();
ProgramElementName name = new ProgramElementName("x");
LocationVariable variable = new LocationVariable(name, KeYJavaType.VOID_TYPE);
pp.printFragment(variable);
Assertions.assertEquals("x", pp.result());
}
}

0 comments on commit 74abc6a

Please sign in to comment.