CadixDev / Mercury

A source transformation and -remapping framework for Java.
Eclipse Public License 2.0
54 stars 23 forks source link

Fix overlapping MultiTextEdits causing conflicts #28

Closed phase closed 3 years ago

phase commented 4 years ago

This takes all of the children in the MutliTextEdit we want to merge and makes them children of the MutliTextEdit being merged into. Conflicts were occurring when one MTE's edit range was overlapping with the others edit range.

I ran this over multiple codebases and this change didn't affect anything other than the static imports that were failing.

stephan-gh commented 4 years ago

Can you add a test for a situation that was failing before and post how the "conflict" looks like (is it some exception)?

phase commented 4 years ago

Added a test case with a failing static import.

Here's the stacktrace:

Caused by: org.eclipse.text.edits.MalformedTreeException: Overlapping text edits
    at org.eclipse.text.edits.TextEdit$InsertionComparator.compare(TextEdit.java:126)
    at org.eclipse.text.edits.TextEdit$InsertionComparator.compare(TextEdit.java:1)
    at java.util.Collections.indexedBinarySearch(Collections.java:334)
    at java.util.Collections.binarySearch(Collections.java:322)
    at org.eclipse.text.edits.TextEdit.computeInsertionIndex(TextEdit.java:799)
    at org.eclipse.text.edits.TextEdit.internalAdd(TextEdit.java:784)
    at org.eclipse.text.edits.TextEdit.addChild(TextEdit.java:340)
    at org.cadixdev.mercury.RewriteContext.combineEdit(RewriteContext.java:105)
    at org.cadixdev.mercury.RewriteContext.rewrite(RewriteContext.java:88)
    at org.cadixdev.mercury.RewriteContext.process(RewriteContext.java:131)
    at org.cadixdev.mercury.Mercury.accept(Mercury.java:222)
jamierocks commented 3 years ago

Merged with https://github.com/CadixDev/Mercury/commit/86723230ee16400ee7626e77c58a0bfdbeb02345.