Search in sources :

Example 1 with TTCN3ReparseUpdater

use of org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater in project titan.EclipsePlug-ins by eclipse.

the class ReconcilingStrategy method reconcileSyntax.

/**
 * Activates incremental reconciling of the syntax of the specified
 * dirty region.
 *
 * @param dirtyRegion
 *                the document region which has been changed
 */
public void reconcileSyntax(final DirtyRegion dirtyRegion) {
    double parserStart = System.nanoTime();
    if (document == null) {
        return;
    }
    int lineBreaks = 0;
    try {
        if (DirtyRegion.INSERT.equals(dirtyRegion.getType())) {
            lineBreaks = calculateLineBreaks(dirtyRegion.getText(), delimeters);
            actualCode.insert(dirtyRegion.getOffset(), dirtyRegion.getText());
        } else {
            lineBreaks = calculateLineBreaks(actualCode.substring(dirtyRegion.getOffset(), dirtyRegion.getOffset() + dirtyRegion.getLength()), delimeters);
            actualCode.delete(dirtyRegion.getOffset(), dirtyRegion.getOffset() + dirtyRegion.getLength());
        }
    } catch (StringIndexOutOfBoundsException e) {
        ErrorReporter.logExceptionStackTrace(e);
        ErrorReporter.logError("String length: " + actualCode.length() + " region type: " + dirtyRegion.getType() + " region offset: " + dirtyRegion.getOffset() + " region length: " + dirtyRegion.getLength() + " region text: '" + dirtyRegion.getText() + "'\n" + "Actual size of the document: " + document.get().length());
        actualCode = new StringBuilder(document.get());
    }
    if (dirtyRegion.getOffset() == 0 && editor != null && document.getLength() == dirtyRegion.getLength()) {
        // thing
        if (!editor.isDirty()) {
            return;
        }
        IPreferencesService prefs = Platform.getPreferencesService();
        if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
            analyze(false);
        }
        return;
    }
    int firstLine;
    try {
        firstLine = document.getLineOfOffset(dirtyRegion.getOffset());
    } catch (BadLocationException e) {
        ErrorReporter.logWarningExceptionStackTrace(e);
        ErrorReporter.logWarning("Offset became invalid, fallback method used. Document length: " + document.getLength() + " region offset: " + dirtyRegion.getOffset());
        firstLine = 0;
    }
    final IFile editedFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (editedFile == null || ResourceExclusionHelper.isExcluded(editedFile)) {
        return;
    }
    final TTCN3ReparseUpdater reparser;
    int length = dirtyRegion.getLength();
    if (DirtyRegion.REMOVE.equals(dirtyRegion.getType())) {
        reparser = new TTCN3ReparseUpdater(editedFile, actualCode.toString(), firstLine + 1, -1 * lineBreaks, dirtyRegion.getOffset(), dirtyRegion.getOffset() + length, -1 * length);
    } else {
        reparser = new TTCN3ReparseUpdater(editedFile, actualCode.toString(), firstLine + 1, lineBreaks, dirtyRegion.getOffset(), dirtyRegion.getOffset(), length);
    }
    final IProject project = editedFile.getProject();
    if (project == null) {
        return;
    }
    if (lastIncrementalSyntaxCheck != null) {
        try {
            lastIncrementalSyntaxCheck.join();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
    lastIncrementalSyntaxCheck = sourceParser.updateSyntax(editedFile, reparser);
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    if (store.getBoolean(PreferenceConstants.DISPLAYDEBUGINFORMATION)) {
        TITANDebugConsole.println("Refreshing the syntax took " + (System.nanoTime() - parserStart) * (1e-9) + " secs");
    }
    WorkspaceJob op = new WorkspaceJob(FOLDING_UPDATE) {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    // TODO optimize for incremental
                    // usage
                    List<Position> positions = (new TTCN3FoldingSupport()).calculatePositions(getDocument());
                    getEditor().updateFoldingStructure(positions);
                }
            });
            return Status.OK_STATUS;
        }
    };
    op.setPriority(Job.LONG);
    op.setSystem(true);
    op.setUser(false);
    op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
    op.setRule(editedFile);
    op.schedule();
}
Also used : IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TTCN3ReparseUpdater(org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater) List(java.util.List) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with TTCN3ReparseUpdater

use of org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater in project titan.EclipsePlug-ins by eclipse.

the class ReconcilingStrategy method reconcile.

@Override
public void reconcile(final DirtyRegion dirtyRegion, final IRegion subRegion) {
    if (editor == null || document == null) {
        return;
    }
    int lineBreaks = 0;
    try {
        if (DirtyRegion.INSERT.equals(dirtyRegion.getType())) {
            actualCode.insert(dirtyRegion.getOffset(), dirtyRegion.getText());
            lineBreaks = org.eclipse.titan.designer.editors.ttcn3editor.ReconcilingStrategy.calculateLineBreaks(dirtyRegion.getText(), document.getLegalLineDelimiters());
        } else {
            lineBreaks = org.eclipse.titan.designer.editors.ttcn3editor.ReconcilingStrategy.calculateLineBreaks(actualCode.substring(dirtyRegion.getOffset(), dirtyRegion.getOffset() + dirtyRegion.getLength()), document.getLegalLineDelimiters());
            actualCode.delete(dirtyRegion.getOffset(), dirtyRegion.getOffset() + dirtyRegion.getLength());
        }
    } catch (StringIndexOutOfBoundsException e) {
        ErrorReporter.logExceptionStackTrace(e);
        ErrorReporter.logError("String length: " + actualCode.length() + " region type: " + dirtyRegion.getType() + " region offset: " + dirtyRegion.getOffset() + " region length: " + dirtyRegion.getLength() + " region text: '" + dirtyRegion.getText() + "'\n" + "Actual size of the document: " + document.get().length());
        actualCode = new StringBuilder(document.get());
    }
    if (dirtyRegion.getOffset() == 0 && document.getLength() == dirtyRegion.getLength()) {
        // thing
        if (!editor.isDirty()) {
            return;
        }
        IPreferencesService prefs = Platform.getPreferencesService();
        if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
            analyze(false);
        }
        return;
    }
    int firstLine;
    try {
        firstLine = document.getLineOfOffset(dirtyRegion.getOffset());
    } catch (BadLocationException e) {
        ErrorReporter.logWarningExceptionStackTrace(e);
        firstLine = 0;
    }
    final IFile editedFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (editedFile == null) {
        return;
    }
    final TTCN3ReparseUpdater reparser;
    int length = dirtyRegion.getLength();
    if (DirtyRegion.INSERT.equals(dirtyRegion.getType())) {
        reparser = new TTCN3ReparseUpdater(editedFile, actualCode.toString(), firstLine + 1, lineBreaks, dirtyRegion.getOffset(), dirtyRegion.getOffset(), length);
    } else {
        reparser = new TTCN3ReparseUpdater(editedFile, actualCode.toString(), firstLine + 1, -1 * lineBreaks, dirtyRegion.getOffset(), dirtyRegion.getOffset() + length, -1 * length);
    }
    final IProject project = editedFile.getProject();
    if (project == null) {
        return;
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
    sourceParser.updateSyntax(editedFile, reparser);
    if (!editor.isSemanticCheckingDelayed()) {
        sourceParser.analyzeAll();
        WorkspaceJob op = new WorkspaceJob(OUTLINEUPDATE) {

            @Override
            public IStatus runInWorkspace(final IProgressMonitor monitor) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        List<Position> positions = (new TTCN3FoldingSupport()).calculatePositions(document);
                        editor.updateFoldingStructure(positions);
                        editor.refreshOutlinePage();
                    }
                });
                return Status.OK_STATUS;
            }
        };
        op.setPriority(Job.LONG);
        op.setSystem(true);
        op.setUser(false);
        op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
        op.setRule(project);
        op.schedule();
    } else {
        sourceParser.reportSyntacticOutdatingOnly(editedFile);
        sourceParser.analyzeAllOnlySyntactically();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TTCN3ReparseUpdater(org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater) List(java.util.List) TTCN3FoldingSupport(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3FoldingSupport) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

List (java.util.List)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)2 TTCN3ReparseUpdater (org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 TTCN3FoldingSupport (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3FoldingSupport)1