Skip to content

Commit 884d590

Browse files
committed
[fix] Never force wildcard generics, fix #77
1 parent cb356a3 commit 884d590

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/java/se/kth/spork/cli/SporkPrettyPrinter.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import spoon.reflect.visitor.DefaultJavaPrettyPrinter;
1111
import spoon.reflect.visitor.DefaultTokenWriter;
1212
import spoon.reflect.visitor.PrinterHelper;
13+
import spoon.reflect.visitor.PrintingContext;
1314

1415
import java.io.IOException;
1516
import java.io.RandomAccessFile;
@@ -65,7 +66,17 @@ public SporkPrettyPrinter scan(CtElement e) {
6566
if (structuralConflict != null) {
6667
writeStructuralConflict(structuralConflict);
6768
} else {
68-
super.scan(e);
69+
if (getContext().forceWildcardGenerics()) {
70+
// Forcing wildcard generics can cause crashes when references can't be resolved, so we don't want
71+
// to do it. An example of where this sometimes causes crashes is if a nested class is used in an
72+
// instanceof check.
73+
try (PrintingContext.Writable _context = getContext().modify()) {
74+
_context.forceWildcardGenerics(false);
75+
super.scan(e);
76+
}
77+
} else {
78+
super.scan(e);
79+
}
6980
}
7081

7182
return this;

0 commit comments

Comments
 (0)