Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public AnnotationBag(String type) {
* @param annotation the annotation to add
*/
public void add(Annotation annotation) {
if (fAnnotations == null)
if (fAnnotations == null) {
fAnnotations= new HashSet<>(2);
}
fAnnotations.add(annotation);
}

Expand All @@ -60,8 +61,9 @@ public void add(Annotation annotation) {
public void remove(Annotation annotation) {
if (fAnnotations != null) {
fAnnotations.remove(annotation);
if (fAnnotations.isEmpty())
if (fAnnotations.isEmpty()) {
fAnnotations= null;
}
}
}

Expand All @@ -82,8 +84,9 @@ public boolean isEmpty() {
* @since 3.1
*/
public Iterator<Annotation> iterator() {
if (!isEmpty())
if (!isEmpty()) {
return fAnnotations.iterator();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ private boolean isCaptionLine(Position position, IDocument document, int line) {
if (position.getOffset() > -1 && position.getLength() > -1) {
try {
int captionOffset;
if (position instanceof IProjectionPosition)
if (position instanceof IProjectionPosition) {
captionOffset= ((IProjectionPosition) position).computeCaptionOffset(document);
else
} else {
captionOffset= 0;
}
int startLine= document.getLineOfOffset(position.getOffset() + captionOffset);
return line == startLine;
} catch (BadLocationException x) {
Expand All @@ -104,15 +105,18 @@ private String getProjectionTextAtLine(ISourceViewer viewer, int line, int numbe
Iterator<Annotation> e= model.getAnnotationIterator();
while (e.hasNext()) {
ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
if (!annotation.isCollapsed())
if (!annotation.isCollapsed()) {
continue;
}

Position position= model.getPosition(annotation);
if (position == null)
if (position == null) {
continue;
}

if (isCaptionLine(position, document, line))
if (isCaptionLine(position, document, line)) {
return getText(document, position.getOffset(), position.getLength(), numberOfLines);
}

}
} catch (BadLocationException x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ public void expand(Annotation annotation) {
*/
public void toggleExpansionState(Annotation annotation) {
if (annotation instanceof ProjectionAnnotation projection) {
if (projection.isCollapsed())
if (projection.isCollapsed()) {
projection.markExpanded();
else
} else {
projection.markCollapsed();
}

modifyAnnotation(projection, true);
}
Expand Down Expand Up @@ -125,8 +126,9 @@ public boolean collapseAll(int offset, int length) {
}
}

if (collapsing)
if (collapsing) {
fireModelChanged();
}

return collapsing;
}
Expand Down Expand Up @@ -162,8 +164,9 @@ protected boolean expandAll(int offset, int length, boolean fireModelChanged) {
}
}

if (expanding && fireModelChanged)
if (expanding && fireModelChanged) {
fireModelChanged();
}

return expanding;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ public ProjectionRulerColumn(int width, IAnnotationAccess annotationAccess) {
@Override
protected void mouseClicked(int line) {
clearCurrentAnnotation();
if (fMouseDownLine != line)
if (fMouseDownLine != line) {
return;
}
ProjectionAnnotation annotation= findAnnotation(line, true);
if (annotation != null) {
ProjectionAnnotationModel model= (ProjectionAnnotationModel) getModel();
Expand All @@ -88,8 +89,9 @@ protected void mouseDown(int rulerLine) {

@Override
protected void mouseDoubleClicked(int rulerLine) {
if (findAnnotation(rulerLine, true) != null)
if (findAnnotation(rulerLine, true) != null) {
return;
}

ProjectionAnnotation annotation= findAnnotation(rulerLine, false);
if (annotation != null) {
Expand Down Expand Up @@ -121,12 +123,14 @@ private ProjectionAnnotation findAnnotation(int line, boolean exact) {
Object next= e.next();
if (next instanceof ProjectionAnnotation annotation) {
Position p= model.getPosition(annotation);
if (p == null)
if (p == null) {
continue;
}

int distance= getDistance(annotation, p, document, line);
if (distance == -1)
if (distance == -1) {
continue;
}

if (!exact) {
if (distance < previousDistance) {
Expand Down Expand Up @@ -167,14 +171,16 @@ private int getDistance(ProjectionAnnotation annotation, Position position, IDoc
if (line < endLine) {
if (annotation.isCollapsed()) {
int captionOffset;
if (position instanceof IProjectionPosition)
if (position instanceof IProjectionPosition) {
captionOffset= ((IProjectionPosition) position).computeCaptionOffset(document);
else
} else {
captionOffset= 0;
}

int captionLine= document.getLineOfOffset(position.getOffset() + captionOffset);
if (startLine <= captionLine && captionLine < endLine)
if (startLine <= captionLine && captionLine < endLine) {
return Math.abs(line - captionLine);
}
}
return line - startLine;
}
Expand Down Expand Up @@ -206,8 +212,9 @@ public Control createControl(CompositeRuler parentRuler, Composite parentControl
control.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseExit(MouseEvent e) {
if (clearCurrentAnnotation())
if (clearCurrentAnnotation()) {
redraw();
}
}
});

Expand All @@ -226,8 +233,9 @@ public void mouseExit(MouseEvent e) {
redraw= true;
}
}
if (redraw)
if (redraw) {
redraw();
}
});
return control;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ public void reset() {
public void run() {
while (true) {
synchronized (fLock) {
if (!fReset)
if (!fReset) {
break;
}
fReset= false;
fProgressMonitor.setCanceled(false);
}
Expand All @@ -81,11 +82,11 @@ public void run() {
}


private ProjectionViewer fProjectionViewer;
private IAnnotationAccess fAnnotationAccess;
private final ProjectionViewer fProjectionViewer;
private final IAnnotationAccess fAnnotationAccess;
private List<String> fConfiguredAnnotationTypes;

private Object fLock= new Object();
private final Object fLock= new Object();
private IProgressMonitor fProgressMonitor;
private volatile Summarizer fSummarizer;

Expand All @@ -112,8 +113,9 @@ public void addAnnotationType(String annotationType) {
if (fConfiguredAnnotationTypes == null) {
fConfiguredAnnotationTypes= new ArrayList<>();
fConfiguredAnnotationTypes.add(annotationType);
} else if (!fConfiguredAnnotationTypes.contains(annotationType))
} else if (!fConfiguredAnnotationTypes.contains(annotationType)) {
fConfiguredAnnotationTypes.add(annotationType);
}
}
}

Expand All @@ -127,8 +129,9 @@ public void removeAnnotationType(String annotationType) {
synchronized (fLock) {
if (fConfiguredAnnotationTypes != null) {
fConfiguredAnnotationTypes.remove(annotationType);
if (fConfiguredAnnotationTypes.isEmpty())
if (fConfiguredAnnotationTypes.isEmpty()) {
fConfiguredAnnotationTypes= null;
}
}
}
}
Expand All @@ -139,22 +142,25 @@ public void removeAnnotationType(String annotationType) {
public void updateSummaries() {
synchronized (fLock) {
if (fConfiguredAnnotationTypes != null) {
if (fSummarizer == null)
if (fSummarizer == null) {
fSummarizer= new Summarizer();
}
fSummarizer.reset();
}
}
}

private void internalUpdateSummaries(IProgressMonitor monitor) {
IAnnotationModel visualAnnotationModel= fProjectionViewer.getVisualAnnotationModel();
if (visualAnnotationModel == null)
if (visualAnnotationModel == null) {
return;
}

removeSummaries(monitor, visualAnnotationModel);

if (isCanceled(monitor))
if (isCanceled(monitor)) {
return;
}

createSummaries(monitor, visualAnnotationModel);
}
Expand All @@ -176,28 +182,32 @@ private void removeSummaries(IProgressMonitor monitor, IAnnotationModel visualAn
while (e.hasNext()) {
Annotation annotation= e.next();
if (annotation instanceof AnnotationBag) {
if (bags == null)
if (bags == null) {
visualAnnotationModel.removeAnnotation(annotation);
else
} else {
bags.add(annotation);
}
}

if (isCanceled(monitor))
if (isCanceled(monitor)) {
return;
}
}

if (bags != null && !bags.isEmpty() && extension != null) {
Annotation[] deletions= new Annotation[bags.size()];
bags.toArray(deletions);
if (!isCanceled(monitor))
if (!isCanceled(monitor)) {
extension.replaceAnnotations(deletions, null);
}
}
}

private void createSummaries(IProgressMonitor monitor, IAnnotationModel visualAnnotationModel) {
ProjectionAnnotationModel model= fProjectionViewer.getProjectionAnnotationModel();
if (model == null)
if (model == null) {
return;
}

Map<Annotation, Position> additions= new HashMap<>();

Expand All @@ -210,26 +220,30 @@ private void createSummaries(IProgressMonitor monitor, IAnnotationModel visualAn
IRegion[] summaryRegions= fProjectionViewer.computeCollapsedRegions(position);
if (summaryRegions != null) {
Position summaryAnchor= fProjectionViewer.computeCollapsedRegionAnchor(position);
if (summaryAnchor != null)
if (summaryAnchor != null) {
createSummary(additions, summaryRegions, summaryAnchor);
}
}
}
}

if (isCanceled(monitor))
if (isCanceled(monitor)) {
return;
}
}

if (!additions.isEmpty()) {
if (visualAnnotationModel instanceof IAnnotationModelExtension extension) {
if (!isCanceled(monitor))
if (!isCanceled(monitor)) {
extension.replaceAnnotations(null, additions);
}
} else {
for (Entry<Annotation, Position> entry : additions.entrySet()) {
AnnotationBag bag= (AnnotationBag) entry.getKey();
Position position= entry.getValue();
if (isCanceled(monitor))
if (isCanceled(monitor)) {
return;
}
visualAnnotationModel.addAnnotation(bag, position);
}
}
Expand All @@ -252,27 +266,31 @@ private void createSummary(Map<Annotation, Position> additions, IRegion[] summar
}
}

if (map == null)
if (map == null) {
return;
}

IAnnotationModel model= fProjectionViewer.getAnnotationModel();
if (model == null)
if (model == null) {
return;
}
Iterator<Annotation> e= model.getAnnotationIterator();
while (e.hasNext()) {
Annotation annotation= e.next();
AnnotationBag bag= findBagForType(map, annotation.getType());
if (bag != null) {
Position position= model.getPosition(annotation);
if (includes(summaryRegions, position))
if (includes(summaryRegions, position)) {
bag.add(annotation);
}
}
}

for (int i= 0; i < size; i++) {
AnnotationBag bag= map.get(fConfiguredAnnotationTypes.get(i));
if (!bag.isEmpty())
if (!bag.isEmpty()) {
additions.put(bag, new Position(summaryAnchor.getOffset(), summaryAnchor.getLength()));
}
}
}

Expand All @@ -290,8 +308,9 @@ private AnnotationBag findBagForType(Map<String, AnnotationBag> bagMap, String a
private boolean includes(IRegion[] regions, Position position) {
for (IRegion region : regions) {
if (position != null && !position.isDeleted()
&& region.getOffset() <= position.getOffset() && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength())
&& region.getOffset() <= position.getOffset() && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength()) {
return true;
}
}
return false;
}
Expand Down
Loading
Loading