use of com.avaloq.tools.ddk.check.runtime.quickfix.ICoreModificationContext in project dsl-devkit by dsldevkit.
the class AbstractQuickFixTest method sortResolutionsByOffsetDecreasing.
/**
* Sort issue resolutions by offset in document decreasing.
*
* @param resolutions
* resolutions to sort
* @return a copy of {@code resolutions} sorted by offset in document decreasing
*/
protected List<IssueResolution> sortResolutionsByOffsetDecreasing(final List<IssueResolution> resolutions) {
final Function<IssueResolution, Integer> getLocationFunction = new Function<IssueResolution, Integer>() {
/**
* {@inheritDoc}
*/
@Override
public Integer apply(final IssueResolution from) {
if (from != null) {
if (from instanceof IssueResolutionWrapper) {
ICoreModificationContext context = ((IssueResolutionWrapper) from).getCoreModificationContext();
if (context instanceof CoreIssueModificationContext) {
return ((CoreIssueModificationContext) context).getIssue().getOffset();
}
} else {
IModificationContext context = from.getModificationContext();
if (context instanceof IssueModificationContext) {
return ((IssueModificationContext) context).getIssue().getOffset();
}
}
}
return Integer.MIN_VALUE;
}
};
Ordering<IssueResolution> ordering = Ordering.natural().onResultOf(getLocationFunction).reverse();
return new ArrayList<IssueResolution>(ordering.sortedCopy(resolutions));
}
Aggregations