use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.DiffRegion in project egit by eclipse.
the class DiffEditorPage method setOverviewAnnotations.
private void setOverviewAnnotations() {
IDocumentProvider documentProvider = getDocumentProvider();
IDocument document = documentProvider.getDocument(getEditorInput());
if (!(document instanceof DiffDocument)) {
return;
}
IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
if (annotationModel == null) {
return;
}
DiffRegion[] diffs = ((DiffDocument) document).getRegions();
if (diffs == null || diffs.length == 0) {
return;
}
Map<Annotation, Position> newAnnotations = new HashMap<>();
for (DiffRegion region : diffs) {
if (DiffRegion.Type.ADD.equals(region.getType())) {
newAnnotations.put(new Annotation(ADD_ANNOTATION_TYPE, true, null), new Position(region.getOffset(), region.getLength()));
} else if (DiffRegion.Type.REMOVE.equals(region.getType())) {
newAnnotations.put(new Annotation(REMOVE_ANNOTATION_TYPE, true, null), new Position(region.getOffset(), region.getLength()));
}
}
if (annotationModel instanceof IAnnotationModelExtension) {
((IAnnotationModelExtension) annotationModel).replaceAnnotations(currentOverviewAnnotations, newAnnotations);
} else {
if (currentOverviewAnnotations != null) {
for (Annotation existing : currentOverviewAnnotations) {
annotationModel.removeAnnotation(existing);
}
}
for (Map.Entry<Annotation, Position> entry : newAnnotations.entrySet()) {
annotationModel.addAnnotation(entry.getKey(), entry.getValue());
}
}
currentOverviewAnnotations = newAnnotations.keySet().toArray(new Annotation[newAnnotations.size()]);
}
use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.DiffRegion in project egit by eclipse.
the class DiffRegionFormatterTest method testRanges.
@Test
public void testRanges() throws Exception {
IDocument document = new Document();
DiffRegion[] regions;
try (DiffRegionFormatter formatter = new DiffRegionFormatter(document)) {
formatter.setRepository(repository);
formatter.format(commit.getTree(), commit.getParent(0).getTree());
assertTrue(document.getLength() > 0);
regions = formatter.getRegions();
}
assertNotNull(regions);
assertTrue(regions.length > 0);
for (DiffRegion region : regions) {
assertNotNull(region);
assertTrue(region.getOffset() >= 0);
assertTrue(region.getLength() >= 0);
assertTrue(region.getOffset() < document.getLength());
}
}
use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.DiffRegion in project egit by eclipse.
the class DiffDocument method getLogicalLine.
int getLogicalLine(int physicalLine, @NonNull DiffEntry.Side side) {
int offset;
try {
offset = getLineOffset(physicalLine);
DiffRegion region = findRegion(offset);
if (region == null) {
return DiffRegion.NO_LINE;
}
int logicalStart = region.getLine(side);
if (logicalStart == DiffRegion.NO_LINE) {
return DiffRegion.NO_LINE;
}
int physicalStart = getLineOfOffset(region.getOffset());
return logicalStart + (physicalLine - physicalStart);
} catch (BadLocationException e) {
return DiffRegion.NO_LINE;
}
}
Aggregations