}
List oldAnnotations = new ArrayList(2);
Iterator annotationIterator = annotationModel.getAnnotationIterator();
while (annotationIterator.hasNext()) {
Annotation annotation = (Annotation) annotationIterator.next();
if (ANNOTATION_TYPE.equals(annotation.getType())) {
annotation.markDeleted(true);
if (DEBUG) {
System.out.println("removing " + annotation); //$NON-NLS-1$
}
oldAnnotations.add(annotation);
}
}
Map newAnnotations = new HashMap();
if (!selection.isEmpty() && selection instanceof IStructuredSelection && selection instanceof ITextSelection) {
Object o = ((IStructuredSelection) selection).getFirstElement();
if (o instanceof IDOMNode) {
int offset = ((ITextSelection) selection).getOffset();
IStructuredDocumentRegion matchRegion = null;
if (((Node) o).getNodeType() == Node.ATTRIBUTE_NODE) {
o = ((Attr) o).getOwnerElement();
}
Position pStart = null;
Position pEnd = null;
String tag = ""; //$NON-NLS-1$
if (o instanceof IDOMNode) {
IDOMNode node = (IDOMNode) o;
IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
if (startStructuredDocumentRegion != null && startStructuredDocumentRegion.containsOffset(offset)) {
if (startStructuredDocumentRegion.getNumberOfRegions() > 1) {
ITextRegion nameRegion = startStructuredDocumentRegion.getRegions().get(1);
pStart = new Position(startStructuredDocumentRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
tag = startStructuredDocumentRegion.getText(nameRegion);
}
matchRegion = ((IDOMNode) o).getEndStructuredDocumentRegion();
if (matchRegion != null && matchRegion.getNumberOfRegions() > 1) {
ITextRegion nameRegion = matchRegion.getRegions().get(1);
pEnd = new Position(matchRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
}
}
else {
IStructuredDocumentRegion endStructuredDocumentRegion = node.getEndStructuredDocumentRegion();
if (endStructuredDocumentRegion != null && endStructuredDocumentRegion.containsOffset(offset)) {
if (endStructuredDocumentRegion.getNumberOfRegions() > 1) {
ITextRegion nameRegion = endStructuredDocumentRegion.getRegions().get(1);
pEnd = new Position(endStructuredDocumentRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
tag = endStructuredDocumentRegion.getText(nameRegion);
}
matchRegion = ((IDOMNode) o).getStartStructuredDocumentRegion();
if (matchRegion != null && matchRegion.getNumberOfRegions() > 1) {
ITextRegion nameRegion = matchRegion.getRegions().get(1);
pStart = new Position(matchRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
}
}
}
}
if (pStart != null && pEnd != null) {
Annotation annotation = new Annotation(ANNOTATION_TYPE, false, NLS.bind(XMLUIMessages.gotoMatchingTag_start, tag));
newAnnotations.put(annotation, pStart);
if (DEBUG) {
System.out.println("adding " + annotation); //$NON-NLS-1$
}
annotation = new Annotation(ANNOTATION_TYPE, false, NLS.bind(XMLUIMessages.gotoMatchingTag_end, tag));
newAnnotations.put(annotation, pEnd);
if (DEBUG) {
System.out.println("adding " + annotation); //$NON-NLS-1$
}
}