use of org.eclipse.titan.designer.AST.ASTLocationChainVisitor in project titan.EclipsePlug-ins by eclipse.
the class OccurencesMarker method doMark.
private void doMark(final IDocument document, final int offset) {
IAnnotationModel annotationModel = getAnnotationModel();
if (annotationModel == null) {
removeOccurences(false);
error(document, offset, "AnnotationModel is null");
return;
}
IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
removeOccurences(false);
error(document, offset, "can not determine the file in the editor.");
return;
}
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
if (projectSourceParser == null) {
removeOccurences(false);
error(document, offset, "Can not find the projectsourceparser for the project: " + file.getProject());
return;
}
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
removeOccurences(false);
error(document, offset, "The module can not be found in the project.");
return;
}
if (printASTElem.getValue()) {
ASTLocationChainVisitor locVisitor = new ASTLocationChainVisitor(offset);
module.accept(locVisitor);
locVisitor.printChain();
}
final Reference reference = getReferenceParser().findReferenceForOpening(file, offset, document);
if (reference == null) {
removeOccurences(false);
// "The reference can not be parsed.");
return;
}
final Location referenceLocaton = reference.getLocation();
if (referenceLocaton.getOffset() == referenceLocaton.getEndOffset()) {
removeOccurences(false);
return;
}
// if (reportDebugInformation) {
// ASTLocationConsistencyVisitor visitor = new
// ASTLocationConsistencyVisitor(document,
// module.get_moduletype()==Module.module_type.TTCN3_MODULE);
// module.accept(visitor);
// }
final List<Hit> result = findOccurrences(document, reference, module, offset);
if (result.isEmpty()) {
return;
}
Map<Annotation, Position> annotationMap = new HashMap<Annotation, Position>();
for (Hit hit : result) {
if (hit.identifier != null) {
int hitOffset = hit.identifier.getLocation().getOffset();
int hitEndOffset = hit.identifier.getLocation().getEndOffset();
if (hitOffset >= 0 && hitEndOffset >= 0 && hitEndOffset >= hitOffset) {
final Annotation annotationToAdd = new Annotation(ANNOTATION_TYPE, false, hit.identifier.getDisplayName());
final Position position = new Position(hitOffset, hitEndOffset - hitOffset);
annotationMap.put(annotationToAdd, position);
}
}
}
synchronized (getLockObject(annotationModel)) {
if (annotationModel instanceof IAnnotationModelExtension) {
((IAnnotationModelExtension) annotationModel).replaceAnnotations(occurrenceAnnotations, annotationMap);
} else {
if (occurrenceAnnotations != null) {
for (Annotation annotationToRemove : occurrenceAnnotations) {
annotationModel.removeAnnotation(annotationToRemove);
}
}
for (Map.Entry<Annotation, Position> entry : annotationMap.entrySet()) {
annotationModel.addAnnotation(entry.getKey(), entry.getValue());
}
}
occurrenceAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
}
}
Aggregations