1 11 package org.eclipse.ant.internal.ui.editor.text; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.ant.internal.ui.AntUIPlugin; 18 import org.eclipse.ant.internal.ui.model.IProblem; 19 import org.eclipse.ant.internal.ui.model.IProblemRequestor; 20 import org.eclipse.jface.text.BadLocationException; 21 import org.eclipse.jface.text.Position; 22 import org.eclipse.jface.text.source.AnnotationModel; 23 import org.eclipse.jface.text.source.AnnotationModelEvent; 24 25 public class AntExternalAnnotationModel extends AnnotationModel implements IProblemRequestor { 26 27 private List fGeneratedAnnotations= new ArrayList (); 28 private List fCollectedProblems= new ArrayList (); 29 30 33 public void acceptProblem(IProblem problem) { 34 fCollectedProblems.add(problem); 35 } 36 37 40 public void endReporting() { 41 boolean temporaryProblemsChanged= false; 42 43 synchronized (getAnnotationMap()) { 44 45 if (fGeneratedAnnotations.size() > 0) { 46 temporaryProblemsChanged= true; 47 removeAnnotations(fGeneratedAnnotations, false, true); 48 fGeneratedAnnotations.clear(); 49 } 50 51 if (fCollectedProblems != null && fCollectedProblems.size() > 0) { 52 Iterator e= fCollectedProblems.iterator(); 53 while (e.hasNext()) { 54 55 IProblem problem= (IProblem) e.next(); 56 57 Position position= createPositionFromProblem(problem); 58 if (position != null) { 59 60 XMLProblemAnnotation annotation= new XMLProblemAnnotation(problem); 61 fGeneratedAnnotations.add(annotation); 62 try { 63 addAnnotation(annotation, position, false); 64 } catch (BadLocationException ex) { 65 AntUIPlugin.log(ex); 66 } 67 68 temporaryProblemsChanged= true; 69 } 70 } 71 72 fCollectedProblems.clear(); 73 } 74 } 75 76 if (temporaryProblemsChanged) 77 fireModelChanged(new AnnotationModelEvent(this)); 78 } 79 80 protected Position createPositionFromProblem(IProblem problem) { 81 int start= problem.getOffset(); 82 if (start >= 0) { 83 int length= problem.getLength(); 84 85 if (length >= 0) 86 return new Position(start, length); 87 } 88 89 return null; 90 } 91 92 95 public void beginReporting() { 96 } 97 } 98 | Popular Tags |