Search in sources :

Example 1 with SpecfileErrorHandler

use of org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler in project linuxtools by eclipse.

the class SpecfileEditor method validateAndMark.

protected void validateAndMark() {
    try {
        IDocument document = getDocumentProvider().getDocument(input);
        SpecfileErrorHandler specfileErrorHandler = new SpecfileErrorHandler(getEditorInput(), document);
        specfileErrorHandler.removeExistingMarkers();
        SpecfileTaskHandler specfileTaskHandler = new SpecfileTaskHandler(getInputFile(), document);
        specfileTaskHandler.removeExistingMarkers();
        this.parser.setErrorHandler(specfileErrorHandler);
        this.parser.setTaskHandler(specfileTaskHandler);
        specfile = parser.parse(document);
    } catch (Exception e) {
        SpecfileLog.logError(e);
    }
}
Also used : SpecfileTaskHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileTaskHandler) SpecfileErrorHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler) IDocument(org.eclipse.jface.text.IDocument) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with SpecfileErrorHandler

use of org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler in project linuxtools by eclipse.

the class SpecStructureCreator method parseSpecfile.

private void parseSpecfile(DocumentRangeNode root, IDocument doc, IFile file) {
    SpecfileParser parser = new SpecfileParser();
    // FIXME: error markers do not show
    if (file != null) {
        FileEditorInput fei = new FileEditorInput(file);
        // without it, the compare editor is blank
        try {
            SpecfileEditor.getSpecfileDocumentProvider().disconnect(fei);
            SpecfileEditor.getSpecfileDocumentProvider().connect(fei);
        } catch (CoreException e) {
            SpecfileLog.logError(e);
        }
        parser.setErrorHandler(new SpecfileErrorHandler(fei, doc));
        parser.setTaskHandler(new SpecfileTaskHandler(fei, doc));
        Specfile specfile = parser.parse(doc);
        String id = specfile.getName();
        // Be a child under parent node of specfileSectionRoot (would be
        // rootNode)
        SpecNode fileNode = new SpecNode((DocumentRangeNode) root.getParentNode(), 1, id, doc, 0, doc.getLength());
        for (SpecfileSection sec : specfile.getSections()) {
            try {
                addNode(root, doc, sec.getName(), doc.getLineOffset(sec.getLineNumber()), doc.getLineOffset(sec.getSectionEndLine()) - doc.getLineOffset(sec.getLineNumber()), 2);
            } catch (BadLocationException e) {
                SpecfileLog.logError(e);
            }
        }
        // Be a child under the parent file node
        for (SpecfilePackage sPackage : specfile.getPackages().getPackages()) {
            try {
                SpecNode pNode = addNode(fileNode, doc, sPackage.getPackageName(), doc.getLineOffset(sPackage.getLineNumber()), doc.getLineOffset(sPackage.getSectionEndLine()) - doc.getLineOffset(sPackage.getLineNumber()), 3);
                for (SpecfileSection section : sPackage.getSections()) {
                    addNode(pNode, doc, section.getName(), doc.getLineOffset(section.getLineNumber()), doc.getLineOffset(section.getSectionEndLine()) - doc.getLineOffset(section.getLineNumber()), 4);
                }
            } catch (BadLocationException e) {
                SpecfileLog.logError(e);
            }
        }
    }
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileTaskHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileTaskHandler) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SpecfileErrorHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) SpecfilePackage(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with SpecfileErrorHandler

use of org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler in project linuxtools by eclipse.

the class RpmlintMarkerVisitor method getSpecfileErrorHandler.

private SpecfileErrorHandler getSpecfileErrorHandler(IFile file, String specContent) {
    if (errorHandler == null) {
        errorHandler = new SpecfileErrorHandler(file, new Document(specContent));
    } else {
        errorHandler.setFile(file);
        errorHandler.setDocument(new Document(specContent));
    }
    return errorHandler;
}
Also used : SpecfileErrorHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with SpecfileErrorHandler

use of org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler in project linuxtools by eclipse.

the class FileTestCase method newFile.

protected void newFile(String contents) {
    try {
        testFile.setContents(new ByteArrayInputStream(contents.getBytes()), false, false, null);
    } catch (CoreException e) {
        fail(e.getMessage());
    }
    testDocument = new Document(contents);
    fei = new FileEditorInput(testFile);
    try {
        SpecfileEditor.getSpecfileDocumentProvider().disconnect(fei);
        SpecfileEditor.getSpecfileDocumentProvider().connect(fei);
    } catch (CoreException e) {
    // let failures occur
    }
    errorHandler = new SpecfileErrorHandler(fei, testDocument);
    parser.setErrorHandler(errorHandler);
    specfile = parser.parse(testDocument);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileEditorInput(org.eclipse.ui.part.FileEditorInput) Document(org.eclipse.jface.text.Document) SpecfileErrorHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler)

Aggregations

SpecfileErrorHandler (org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler)4 CoreException (org.eclipse.core.runtime.CoreException)3 Document (org.eclipse.jface.text.Document)2 IDocument (org.eclipse.jface.text.IDocument)2 SpecfileTaskHandler (org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileTaskHandler)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Specfile (org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)1 SpecfilePackage (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage)1 SpecfileParser (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser)1 SpecfileSection (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection)1