Search in sources :

Example 1 with TTCN3FoldingSupport

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3FoldingSupport in project titan.EclipsePlug-ins by eclipse.

the class ReconcilingStrategy method fullReconciliation.

private void fullReconciliation(final boolean isInitial) {
    actualCode = new StringBuilder(document.get());
    GlobalIntervalHandler.putInterval(document, null);
    IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
        analyze(isInitial);
    } else {
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                List<Position> positions = (new TTCN3FoldingSupport()).calculatePositions(document);
                editor.updateFoldingStructure(positions);
                editor.updateOutlinePage();
            }
        });
    }
}
Also used : List(java.util.List) TTCN3FoldingSupport(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3FoldingSupport) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 2 with TTCN3FoldingSupport

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3FoldingSupport 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)

Example 3 with TTCN3FoldingSupport

use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3FoldingSupport in project titan.EclipsePlug-ins by eclipse.

the class ReconcilingStrategy method analyze.

public void analyze(final boolean isInitial) {
    final IFile editedFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (editedFile == null || ResourceExclusionHelper.isExcluded(editedFile)) {
        return;
    }
    IProject project = editedFile.getProject();
    if (project == null) {
        return;
    }
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            List<Position> positions = (new TTCN3FoldingSupport()).calculatePositions(document);
            getEditor().updateFoldingStructure(positions);
        }
    });
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    if (isInitial || !editor.isSemanticCheckingDelayed()) {
        projectSourceParser.reportOutdating(editedFile);
        projectSourceParser.analyzeAll();
        WorkspaceJob op = new WorkspaceJob(OUTLINEUPDATE) {

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

                    @Override
                    public void run() {
                        if (!MarkerHandler.hasMarker(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, editedFile)) {
                            getEditor().updateOutlinePage();
                        }
                        Module module = projectSourceParser.containedModule(editedFile);
                        if (module != null && module instanceof TTCN3Module) {
                            final List<Location> icList = ((TTCN3Module) module).getInactiveCodeLocations();
                            getEditor().updateInactiveCodeAnnotations(icList);
                        }
                    }
                });
                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 {
        projectSourceParser.reportSyntacticOutdatingOnly(editedFile);
        projectSourceParser.analyzeAllOnlySyntactically();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) List(java.util.List) TTCN3FoldingSupport(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3FoldingSupport) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Aggregations

List (java.util.List)3 TTCN3FoldingSupport (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3FoldingSupport)3 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 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)2 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Module (org.eclipse.titan.designer.AST.Module)1 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)1 TTCN3ReparseUpdater (org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater)1