Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix program element printing in proof saver #3073

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions key.core/src/main/java/de/uka/ilkd/key/pp/PrettyPrinter.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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());
}
}