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
I'm trying to reorder the parameters in a constructor creation expr.
The first thing I've tried is to reorder the NodeList => Not sucessful (Looked normal since the parent is not aware of the sorting)
Second thing I've tried it to replace it manually, see code below:
Map<Integer, Expression> positionToParameterMap = newHashMap<>();
NodeList<Expression> arguments = constructorCallExpr.getArguments();
for (inti = 0; i < arguments.size(); i++) {
positionToParameterMap.put(i, arguments.get(i));
}
for (Pair<Integer, Integer> deltaPair : constructorChanges.deltaChanges) {
Expressionexpression = positionToParameterMap.get(deltaPair.getValue()); // map to element at previous positionconstructorCallExpr.setArgument(deltaPair.getKey(), expression); // Replace element at new position with element from previous position
}
This code above throws:
Caused by: java.lang.IllegalArgumentException: fromIndex(116) > toIndex(73)
at java.util.SubList.<init>(AbstractList.java:624)
at java.util.AbstractList.subList(AbstractList.java:484)
at com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator$CalculatedSyntaxModel.sub(LexicalDifferenceCalculator.java:66)
at com.github.javaparser.printer.lexicalpreservation.DifferenceElementCalculator.calculate(DifferenceElementCalculator.java:144)
at com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.calculateListReplacementDifference(LexicalDifferenceCalculator.java:132)
at com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter$Observer.concreteListReplacement(LexicalPreservingPrinter.java:307)
at com.github.javaparser.ast.observer.PropagatingAstObserver.listReplacement(PropagatingAstObserver.java:82)
at com.github.javaparser.ast.NodeList.lambda$notifyElementReplaced$3(NodeList.java:474)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at com.github.javaparser.ast.NodeList.notifyElementReplaced(NodeList.java:474)
at com.github.javaparser.ast.NodeList.set(NodeList.java:147)
at com.github.javaparser.ast.nodeTypes.NodeWithArguments.setArgument(NodeWithArguments.java:55)
Any idea why? Am I doing something I shouldn't be doing? If no, is there a workaround for this?
The text was updated successfully, but these errors were encountered:
I'm trying to reorder the parameters in a constructor creation expr.
The first thing I've tried is to reorder the NodeList => Not sucessful (Looked normal since the parent is not aware of the sorting)
Second thing I've tried it to replace it manually, see code below:
This code above throws:
Any idea why? Am I doing something I shouldn't be doing? If no, is there a workaround for this?
The text was updated successfully, but these errors were encountered: