Search in sources :

Example 86 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project titan.EclipsePlug-ins by eclipse.

the class ParserMarkerSupport method createOnTheFlySyntacticMarker.

public static void createOnTheFlySyntacticMarker(final IFile file, final SyntacticErrorStorage errorStorage, final int severity) {
    if (!file.isAccessible()) {
        return;
    }
    int lineNumber = errorStorage.lineNumber;
    int charStart = errorStorage.charStart;
    int charEnd = errorStorage.charEnd;
    String message = errorStorage.message;
    boolean justDoIt = errorStorage.exceptionType == SyntacticErrorStorage.ExceptionType.LEXER_NOVIABLEALT_EXCEPTION;
    try {
        if (justDoIt && lineNumber >= 0) {
            IDocument document = null;
            ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
            IPath fullPath = file.getFullPath();
            if (manager != null) {
                manager.connect(fullPath, LocationKind.IFILE, null);
                ITextFileBuffer buffer = manager.getTextFileBuffer(fullPath, LocationKind.IFILE);
                document = buffer.getDocument();
            }
            try {
                if (document != null && lineNumber > 0 && lineNumber <= document.getNumberOfLines()) {
                    charStart = document.getLineOffset(lineNumber - 1);
                    charEnd = document.getLineOffset(lineNumber - 1);
                    charStart += errorStorage.charStart;
                    charEnd += errorStorage.charEnd;
                }
            } catch (BadLocationException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
        }
        Location location = new Location(file, lineNumber, charStart, charEnd);
        location.reportSingularExternalProblem(message, severity, GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Location(org.eclipse.titan.designer.AST.Location)

Example 87 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project titan.EclipsePlug-ins by eclipse.

the class ParserMarkerSupport method createOnTheFlyMixedMarker.

/**
 * Places an on-the-fly error marker on the provided file. If the file
 * is being edited in an editor the marker is reported and must be
 * placed on the document edited, not on the file in the file system. In
 * this form it is possible to provide a location as a region that was
 * originally housing the erroneous location. This is used as syntactic marker
 * but placed during semantic check
 *
 * @param file
 *                the file which seems to be erroneous
 * @param errorStorage
 *                the info extracted from the caught exception(s)
 * @param severity
 *                the severity level of the error
 */
public static void createOnTheFlyMixedMarker(final IFile file, final SyntacticErrorStorage errorStorage, final int severity) {
    if (!file.isAccessible()) {
        return;
    }
    int lineNumber = errorStorage.lineNumber;
    int charStart = errorStorage.charStart;
    int charEnd = errorStorage.charEnd;
    String message = errorStorage.message;
    boolean justDoIt = errorStorage.exceptionType == SyntacticErrorStorage.ExceptionType.LEXER_NOVIABLEALT_EXCEPTION;
    try {
        if (justDoIt && lineNumber >= 0) {
            IDocument document = null;
            ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
            IPath fullPath = file.getFullPath();
            if (manager != null) {
                manager.connect(fullPath, LocationKind.IFILE, null);
                ITextFileBuffer buffer = manager.getTextFileBuffer(fullPath, LocationKind.IFILE);
                document = buffer.getDocument();
            }
            try {
                if (document != null && lineNumber > 0 && lineNumber <= document.getNumberOfLines()) {
                    charStart = document.getLineOffset(lineNumber - 1);
                    charEnd = document.getLineOffset(lineNumber - 1);
                    charStart += errorStorage.charStart;
                    charEnd += errorStorage.charEnd;
                }
            } catch (BadLocationException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
        }
        Location location = new Location(file, lineNumber, charStart, charEnd);
        location.reportSingularExternalProblem(message, severity, GeneralConstants.ONTHEFLY_MIXED_MARKER);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)87 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)66 IDocument (org.eclipse.jface.text.IDocument)54 IPath (org.eclipse.core.runtime.IPath)52 CoreException (org.eclipse.core.runtime.CoreException)36 BadLocationException (org.eclipse.jface.text.BadLocationException)26 IFile (org.eclipse.core.resources.IFile)22 Test (org.junit.Test)17 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 IOException (java.io.IOException)10 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)10 IResource (org.eclipse.core.resources.IResource)8 Path (org.eclipse.core.runtime.Path)8 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)7 TextEdit (org.eclipse.text.edits.TextEdit)7 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)6 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)6 UndoEdit (org.eclipse.text.edits.UndoEdit)6 FileNotFoundException (java.io.FileNotFoundException)5 MalformedURLException (java.net.MalformedURLException)5