Search in sources :

Example 31 with ProjectSourceParser

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

the class MinimizeScopeActionFromEditor method findSelection.

private Definition findSelection() {
    // getting the active editor
    final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    TTCN3Editor targetEditor;
    if (editor == null || !(editor instanceof TTCN3Editor)) {
        return null;
    } else {
        targetEditor = (TTCN3Editor) editor;
    }
    final IStatusLineManager statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
    // getting current selection
    final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    final TextSelection textSelection = extractSelection(selectionService.getSelection());
    // iterating through part of the module
    final IResource selectedRes = extractResource(targetEditor);
    if (!(selectedRes instanceof IFile)) {
        ErrorReporter.logError("SelectionFinder.findSelection(): Selected resource `" + selectedRes.getName() + "' is not a file.");
        return null;
    }
    final IFile selectedFile = (IFile) selectedRes;
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(selectedFile.getProject());
    final Module selectedModule = projectSourceParser.containedModule(selectedFile);
    // getting current selection nodes
    final int selectionOffset = textSelection.getOffset() + textSelection.getLength();
    final SelectionFinderVisitor selVisitor = new SelectionFinderVisitor(selectionOffset);
    selectedModule.accept(selVisitor);
    final Definition selectedDef = selVisitor.getSelection();
    if (selectedDef == null) {
        ErrorReporter.logWarning("SelectionFinder.findSelection(): Visitor did not find a definition in the selection.");
        statusLineManager.setErrorMessage(ERR_MSG_NO_SELECTION);
        return null;
    }
    return selectedDef;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) TextSelection(org.eclipse.jface.text.TextSelection) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ISelectionService(org.eclipse.ui.ISelectionService) IEditorPart(org.eclipse.ui.IEditorPart) Module(org.eclipse.titan.designer.AST.Module) IResource(org.eclipse.core.resources.IResource) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 32 with ProjectSourceParser

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

the class ProjectHandlingLibrary method analyzeProject.

/**
 * Starts the analysis of its project and waits until it finishes.
 */
public void analyzeProject() {
    ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
    WorkspaceJob job = sourceParser.analyzeAll();
    while (job == null) {
        try {
            Thread.sleep(500);
            job = sourceParser.analyzeAll();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    try {
        job.join();
    } catch (InterruptedException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    AnalyzerCache.withPreference().analyzeProject(new NullProgressMonitor(), project).showAll(project);
    try {
        // Wait for the markers to show up
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 33 with ProjectSourceParser

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

the class Expectation method runTest.

public void runTest() {
    Map<String, List<Integer>> actualMarkers = new HashMap<String, List<Integer>>();
    // analyze the modules, and collect the related markers
    IProject project = WorkspaceHandlingLibrary.getWorkspace().getRoot().getProject(CustomConfigurable.PROJECT_TO_USE);
    ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
    for (String modName : expectedMarkers.keySet()) {
        Module mod = parser.getModuleByName(modName);
        IResource file = mod.getLocation().getFile();
        MarkerHandler mh = Analyzer.builder().addProblem(type).build().analyzeModule(new NullProgressMonitor(), mod);
        List<Integer> lines = new ArrayList<Integer>();
        for (Marker m : mh.get(file)) {
            if (m.getProblemType() == type && m.getLine() != -1) {
                lines.add(m.getLine());
            }
        }
        // save the line number of markers that were from our problem type
        actualMarkers.put(modName, lines);
    }
    // check whether the reality complies our expectations
    for (String modName : expectedMarkers.keySet()) {
        for (Integer ln : expectedMarkers.get(modName)) {
            if (!actualMarkers.get(modName).remove(ln)) {
                fail("We expected a marker in " + modName + " at line " + ln + ", but have not found it");
            }
        }
    }
    // Check whether we managed to consume all markers that showed up during the analysis
    for (String modName : actualMarkers.keySet()) {
        for (Integer ln : actualMarkers.get(modName)) {
            fail("Unexpected marker in " + modName + " at line " + ln);
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Marker(org.eclipse.titanium.markers.handler.Marker) IMarker(org.eclipse.core.resources.IMarker) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) ArrayList(java.util.ArrayList) List(java.util.List) Module(org.eclipse.titan.designer.AST.Module) MarkerHandler(org.eclipse.titanium.markers.handler.MarkerHandler) IResource(org.eclipse.core.resources.IResource)

Example 34 with ProjectSourceParser

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

the class ReferenceFinder method findAllReferences.

public Map<Module, List<Hit>> findAllReferences(final Module module, final IProject project, final IProgressMonitor pMonitor, final boolean reportDebugInformation) {
    final IProgressMonitor monitor = pMonitor == null ? new NullProgressMonitor() : pMonitor;
    final List<IProject> relatedProjects = ProjectBasedBuilder.getProjectBasedBuilder(project).getAllReferencingProjects();
    relatedProjects.addAll(ProjectBasedBuilder.getProjectBasedBuilder(project).getAllReachableProjects());
    if (!relatedProjects.contains(project)) {
        relatedProjects.add(project);
    }
    int size = 0;
    for (IProject tempProject : relatedProjects) {
        size += GlobalParser.getProjectSourceParser(tempProject).getModules().size();
    }
    monitor.beginTask("Searching references.", size);
    final Map<Module, List<Hit>> foundIdsMap = new HashMap<Module, List<Hit>>();
    // in this scope
    // TODO this is efficient but only for local variables ... and if are not followed up by other searches
    List<Hit> foundIds = new ArrayList<Hit>();
    scope.findReferences(this, foundIds);
    if (!foundIds.isEmpty()) {
        foundIdsMap.put(scope.getModuleScope(), foundIds);
    }
    // FIXME but if component variable ... we might have to search all related modules in all related projects.
    if (scope instanceof Module) {
        for (IProject project2 : relatedProjects) {
            final ProjectSourceParser projectSourceParser2 = GlobalParser.getProjectSourceParser(project2);
            for (Module module2 : projectSourceParser2.getModules()) {
                if (monitor.isCanceled()) {
                    return foundIdsMap;
                }
                for (Module m : module2.getImportedModules()) {
                    if (m == scope) {
                        if (reportDebugInformation) {
                            TITANDebugConsole.println("found importing module: " + module2.getName());
                        }
                        foundIds = new ArrayList<Hit>();
                        module2.findReferences(this, foundIds);
                        if (!foundIds.isEmpty()) {
                            foundIdsMap.put(module2, foundIds);
                        }
                        break;
                    }
                }
                monitor.worked(1);
            }
        }
    }
    monitor.done();
    return foundIdsMap;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)

Example 35 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser 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)

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