You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #3935, some issue led to a workaround requesting to drop all modifiers (before applying new ones). This workaround leads to issue with LexicalPreservingPrinter and sealed classes (JDK17).
Here is a reproduction case:
import com.github.javaparser.ParserConfiguration;
import com.github.javaparser.ParserConfiguration.LanguageLevel;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter;
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
// https://github.com/solven-eu/cleanthat/issues/713
public class SealedPermitsParsing {
static final String testCase =
"public sealed interface IUpdatePortCommand permits UpdateScheduleCommand, UpdateStateCommand {}";
public static void main(String[] args) {
System.out.println(testCase);
ParserConfiguration parserConfiguration = new ParserConfiguration();
parserConfiguration.setLanguageLevel(LanguageLevel.JAVA_17);
StaticJavaParser.setConfiguration(
parserConfiguration.setSymbolResolver(new JavaSymbolSolver(new ReflectionTypeSolver(true))));
var unit = StaticJavaParser.parse(testCase);
unit = LexicalPreservingPrinter.setup(unit);
ClassOrInterfaceDeclaration classOrInterface = unit.findFirst(ClassOrInterfaceDeclaration.class).get();
classOrInterface.setModifiers();
System.out.println(classOrInterface);
}
}
It fails with:
Exception in thread "main" java.lang.UnsupportedOperationException: Csm token CsmToken(property:{) NodeText TOKEN "permits" <46> (line 1,col 44)-(line 1,col 50)
at com.github.javaparser.printer.lexicalpreservation.Difference.applyKeptDiffElement(Difference.java:655)
at com.github.javaparser.printer.lexicalpreservation.Difference.apply(Difference.java:363)
at com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.calculatePropertyChange(LexicalDifferenceCalculator.java:176)
at com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter$Observer.concretePropertyChange(LexicalPreservingPrinter.java:199)
at com.github.javaparser.ast.observer.PropagatingAstObserver.propertyChange(PropagatingAstObserver.java:62)
at com.github.javaparser.ast.Node.lambda$notifyPropertyChange$7(Node.java:629)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at com.github.javaparser.ast.Node.notifyPropertyChange(Node.java:629)
at com.github.javaparser.ast.body.TypeDeclaration.setModifiers(TypeDeclaration.java:133)
at com.github.javaparser.ast.body.TypeDeclaration.setModifiers(TypeDeclaration.java:51)
at com.github.javaparser.ast.nodeTypes.NodeWithModifiers.setModifiers(NodeWithModifiers.java:96)
at eu.solven.cleanthat.engine.java.refactorer.report_javaparser.SealedPermitsParsing.main(SealedPermitsParsing.java:43)
The text was updated successfully, but these errors were encountered:
In #3935, some issue led to a workaround requesting to drop all modifiers (before applying new ones). This workaround leads to issue with
LexicalPreservingPrinter
andsealed
classes (JDK17).Here is a reproduction case:
It fails with:
The text was updated successfully, but these errors were encountered: