1 package net.mograsim.plugin.asm.editor;
3 import java.io.StringReader;
5 import javax.xml.parsers.DocumentBuilder;
6 import javax.xml.parsers.DocumentBuilderFactory;
8 import org.eclipse.core.resources.IFile;
9 import org.eclipse.core.resources.IMarker;
10 import org.eclipse.core.runtime.CoreException;
11 import org.eclipse.jface.text.DocumentEvent;
12 import org.eclipse.jface.text.IDocumentListener;
13 import org.xml.sax.InputSource;
14 import org.xml.sax.SAXParseException;
16 public class AsmDocumentValidator implements IDocumentListener
19 private final IFile file;
20 private IMarker marker;
22 AsmDocumentValidator(IFile file)
28 public void documentChanged(DocumentEvent event)
30 if (this.marker != null)
36 catch (CoreException e)
42 try (StringReader reader = new StringReader(event.getDocument().get());)
44 DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
45 documentBuilder.parse(new InputSource(reader));
51 this.marker = file.createMarker(IMarker.PROBLEM);
52 this.marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
53 this.marker.setAttribute(IMarker.MESSAGE, ex.getMessage());
54 if (ex instanceof SAXParseException)
56 SAXParseException saxParseException = (SAXParseException) ex;
57 int lineNumber = saxParseException.getLineNumber();
58 int offset = event.getDocument().getLineInformation(lineNumber - 1).getOffset() + saxParseException.getColumnNumber()
60 this.marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
61 this.marker.setAttribute(IMarker.CHAR_START, offset);
62 this.marker.setAttribute(IMarker.CHAR_END, offset + 1);
73 public void documentAboutToBeChanged(DocumentEvent event)