Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.2k
Open
Description
importorg.junit.jupiter.api.Test;importcom.github.javaparser.JavaParser;importcom.github.javaparser.ast.expr.InstanceOfExpr;importcom.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter;publicclassJavaParserBugsTest {@TestvoidtestUnsupportedOperationExceptionRemovingPattern() {varparser =newJavaParser();varcu =parser.parse(""" public class PatternMatching_UnsupportedOperationException { public void processObject(Object obj) { if (obj instanceof String s) { System.out.println(s); } } } """).getResult().orElseThrow();LexicalPreservingPrinter.setup(cu);cu.findAll(InstanceOfExpr.class).forEach(InstanceOfExpr::removePattern); }}
Fails with:
NodeText: NodeText{[ChildTextElement{obj}, " " <1> (line 3,col 16)-(line 3,col 16), "instanceof" <37> (line 3,col 17)-(line 3,col 26), " " <1> (line 3,col 27)-(line 3,col 27), ChildTextElement{String}, ChildTextElement{String s}]}. Difference: Difference{[Kept{child(NameExpr)}, Kept{CsmToken(property: )}, Kept{CsmToken(property:instanceof)}, Kept{CsmToken(property: )}, Kept{child(ClassOrInterfaceType)}]} ChildTextElement{String s}java.lang.UnsupportedOperationException: NodeText: NodeText{[ChildTextElement{obj}, " " <1> (line 3,col 16)-(line 3,col 16), "instanceof" <37> (line 3,col 17)-(line 3,col 26), " " <1> (line 3,col 27)-(line 3,col 27), ChildTextElement{String}, ChildTextElement{String s}]}. Difference: Difference{[Kept{child(NameExpr)}, Kept{CsmToken(property: )}, Kept{CsmToken(property:instanceof)}, Kept{CsmToken(property: )}, Kept{child(ClassOrInterfaceType)}]} ChildTextElement{String s}at com.github.javaparser.printer.lexicalpreservation.Difference.applyLeftOverOriginalElements(Difference.java:416)at com.github.javaparser.printer.lexicalpreservation.Difference.apply(Difference.java:379)at com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.calculatePropertyChange(LexicalDifferenceCalculator.java:181)at com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter$Observer.concretePropertyChange(LexicalPreservingPrinter.java:204)at com.github.javaparser.ast.observer.PropagatingAstObserver.propertyChange(PropagatingAstObserver.java:64)at com.github.javaparser.ast.Node.lambda$notifyPropertyChange$7(Node.java:675)at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)at com.github.javaparser.ast.Node.notifyPropertyChange(Node.java:675)at com.github.javaparser.ast.expr.InstanceOfExpr.setPattern(InstanceOfExpr.java:269)at com.github.javaparser.ast.expr.InstanceOfExpr.removePattern(InstanceOfExpr.java:225)