Search in sources :

Example 26 with ProjectSourceParser

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

the class OutlinePage method getModule.

private Module getModule() {
    final IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        return null;
    }
    // FIXME add semantic check guard on project level.
    ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    return sourceParser.containedModule(file);
}
Also used : IFile(org.eclipse.core.resources.IFile) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 27 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser 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(getDocument());
            getEditor().updateFoldingStructure(positions);
        }
    });
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    if (isInitial || !TTCN3Editor.isSemanticCheckingDelayed()) {
        if (!isInitial) {
            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();
                        }
                    }
                });
                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) IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) List(java.util.List) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 28 with ProjectSourceParser

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

the class ReconcilingStrategy method reconcileSemantics.

/**
 * Activates reconciling of the semantic meanings.
 */
public void reconcileSemantics() {
    final IFile editedFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (editedFile == null || ResourceExclusionHelper.isExcluded(editedFile)) {
        return;
    }
    final WorkspaceJob tempLastIncrementalSyntaxCheck = lastIncrementalSyntaxCheck;
    if (tempLastIncrementalSyntaxCheck != null) {
        try {
            tempLastIncrementalSyntaxCheck.join();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    IProject project = editedFile.getProject();
    if (project == null) {
        return;
    }
    TITANDebugConsole.println("Reconciling semantics at " + System.nanoTime() + " time.");
    ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
    sourceParser.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().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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 29 with ProjectSourceParser

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

the class TTCN3Editor method analyzeOpenedFile.

/**
 * Analyze or reanalyze the file opened in the current editor in case of semantic check is delayed.
 * <p>
 * It is necessary if
 * <p> - if the file is just saved OR
 * <p> - if the file is just opened and therefore it contain just partial semantic check information
 *   (This is the case when functionality "minimized memory usage" is switched on)
 *
 * @param jobname The name of the workspace job
 * @param file the file being saved
 * @author Kristof Szabados
 */
private void analyzeOpenedFile(final String jobname, final IFile file) {
    if (file != null && TTCN3Editor.isSemanticCheckingDelayed()) {
        final IReconcilingStrategy strategy = reconciler.getReconcilingStrategy(IDocument.DEFAULT_CONTENT_TYPE);
        if (strategy instanceof ReconcilingStrategy) {
            WorkspaceJob op = new WorkspaceJob(jobname) {

                @Override
                public IStatus runInWorkspace(final IProgressMonitor monitor) {
                    if (reconciler.isIncrementalReconciler()) {
                        ((ReconcilingStrategy) strategy).reconcileSemantics();
                    } else {
                        ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
                        projectSourceParser.reportOutdating(file);
                        ((ReconcilingStrategy) strategy).analyze(true);
                    }
                    return Status.OK_STATUS;
                }
            };
            op.setPriority(Job.LONG);
            op.setSystem(true);
            op.setUser(false);
            op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
            op.schedule();
        }
    }
}
Also used : IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 30 with ProjectSourceParser

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

the class ChangeCreator method createFileChange.

/**
 * Creates the {@link #change} object, which contains all the inserted and edited texts
 * in the selected resources.
 */
private Change createFileChange(final IFile toVisit) {
    if (toVisit == null) {
        return null;
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
    final Module module = sourceParser.containedModule(toVisit);
    if (module == null) {
        return null;
    }
    // 
    // collect functions
    Set<Definition> funcs;
    final FunctionCollector vis = new FunctionCollector();
    if (defSelection == null) {
        module.accept(vis);
        funcs = vis.getResult();
    } else {
        if (defSelection instanceof Def_Function || defSelection instanceof Def_Testcase) {
            // TODO any other possibilities for the type of 'defSelection'?
            funcs = new HashSet<Definition>();
            funcs.add(defSelection);
        } else {
            ErrorReporter.logError("Variable scope reduction called for " + defSelection.getIdentifier().getDisplayName() + ", but it is only supported for functions and testcases. ");
            return null;
        }
    }
    // create edits
    final List<Edit> allEdits = new ArrayList<Edit>();
    for (Definition def : funcs) {
        final List<Edit> edits = analyzeFunction(def);
        if (edits == null) {
            continue;
        }
        allEdits.addAll(edits);
    }
    if (allEdits.isEmpty()) {
        return null;
    }
    final String fileContents = loadFileContent(toVisit);
    // create text edits
    // 
    final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
    final MultiTextEdit rootEdit = new MultiTextEdit();
    tfc.setEdit(rootEdit);
    // TODO this is an O(n^2) algorithm
    // merge overlapping DeleteEdits
    // used, when removing all parts of a multi-declaration statement:
    // the DeleteEdit for removing the last part covers all the DeleteEdits for the other parts
    // WARNING merging edits might make debugging more difficult, since the overlapping edit errors are avoided
    final List<TextEdit> allTes = new LinkedList<TextEdit>();
    // collect processed (insert) edits with their created insert edit
    final Map<Edit, InsertEdit> editsDone = new HashMap<Edit, InsertEdit>();
    for (Edit e : allEdits) {
        final TextEdit[] tes = createTextEdit(toVisit, fileContents, e, editsDone);
        for (TextEdit te : tes) {
            if (!(te instanceof DeleteEdit)) {
                allTes.add(te);
                // System.err.println("$ nonde added: " + te.getOffset() + "-" + te.getExclusiveEnd());
                continue;
            }
            DeleteEdit dte = (DeleteEdit) te;
            final ListIterator<TextEdit> it = allTes.listIterator();
            while (it.hasNext()) {
                final TextEdit currTe = it.next();
                if (!(currTe instanceof DeleteEdit)) {
                    continue;
                }
                final DeleteEdit currDte = (DeleteEdit) currTe;
                // if the new edit (dte) overlaps currDte, merge them
                if (doesDeleteEditsOverlap(dte, currDte)) {
                    // System.err.println("$ de removed: " + currDte.getOffset() + "-" + currDte.getExclusiveEnd());
                    it.remove();
                    dte = mergeDeleteEdits(dte, currDte);
                // System.err.println("$ merged des: " + dte.getOffset() + "-" + dte.getExclusiveEnd());
                }
            }
            // System.err.println("$ de added: " + dte.getOffset() + "-" + dte.getExclusiveEnd());
            allTes.add(dte);
        }
    }
    Collections.reverse(allTes);
    for (TextEdit te : allTes) {
        rootEdit.addChild(te);
    }
    return tfc;
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) HashMap(java.util.HashMap) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ArrayList(java.util.ArrayList) Edit(org.eclipse.titanium.refactoring.scope.nodes.Edit) InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) DeleteEdit(org.eclipse.text.edits.DeleteEdit) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) LinkedList(java.util.LinkedList) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) Module(org.eclipse.titan.designer.AST.Module) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Aggregations

ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)72 Module (org.eclipse.titan.designer.AST.Module)51 IFile (org.eclipse.core.resources.IFile)34 ArrayList (java.util.ArrayList)23 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)23 IProject (org.eclipse.core.resources.IProject)19 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)14 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)12 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)11 Identifier (org.eclipse.titan.designer.AST.Identifier)11 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)10 Location (org.eclipse.titan.designer.AST.Location)10 List (java.util.List)9 Reference (org.eclipse.titan.designer.AST.Reference)9 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)9 CoreException (org.eclipse.core.runtime.CoreException)8 TextSelection (org.eclipse.jface.text.TextSelection)8 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7