Search in sources :

Example 86 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.

the class ReconcilingStrategy method fullReconciliation.

private void fullReconciliation(final boolean isInitial) {
    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 ASN1FoldingSupport()).calculatePositions(document);
                editor.updateFoldingStructure(positions);
                final IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
                if (!MarkerHandler.hasMarker(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, file) || !MarkerHandler.hasMarker(GeneralConstants.ONTHEFLY_MIXED_MARKER, file)) {
                    getEditor().updateOutlinePage();
                }
            }
        });
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) List(java.util.List) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 87 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.

the class RenameRefactoring method runAction.

/**
 * Helper function used by RenameRefactoringAction classes for TTCN-3,
 * ASN.1 and TTCNPP editors
 */
public static void runAction(final IEditorPart targetEditor, final ISelection selection) {
    final IStatusLineManager statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
    statusLineManager.setErrorMessage(null);
    final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        statusLineManager.setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        statusLineManager.setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    final IPreferencesService prefs = Platform.getPreferencesService();
    final boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (selection instanceof TextSelection && !selection.isEmpty() && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.getConsole().newMessageStream().println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((IEditorWithCarretOffset) targetEditor).getCarretOffset();
    }
    // run semantic analysis to have up-to-date AST
    // FIXME: it does not work for incremental parsing
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final WorkspaceJob job = projectSourceParser.analyzeAll();
    if (job == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.getConsole().newMessageStream().println("Rename refactoring: WorkspaceJob to analyze project could not be created.");
        }
        return;
    }
    try {
        job.join();
    } catch (InterruptedException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return;
    }
    // find the module
    if (ResourceExclusionHelper.isExcluded(file)) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
        return;
    }
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        statusLineManager.setErrorMessage(MessageFormat.format(NOTFOUNDMODULE, file.getName()));
        return;
    }
    ReferenceFinder rf = findOccurrencesLocationBased(module, offset);
    if (rf == null) {
        rf = new ReferenceFinder();
        boolean isDetected = rf.detectAssignmentDataByOffset(module, offset, targetEditor, true, reportDebugInformation);
        if (!isDetected) {
            return;
        }
    }
    RenameRefactoring renameRefactoring = new RenameRefactoring(file, module, rf);
    RenameRefactoringWizard renameWizard = new RenameRefactoringWizard(renameRefactoring);
    RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(renameWizard);
    try {
        operation.run(targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
        // operation was canceled
        if (reportDebugInformation) {
            TITANDebugConsole.getConsole().newMessageStream().println("Rename refactoring has been cancelled");
        }
    } finally {
        // ===================================
        // === Re-analysis after renaming ====
        // ===================================
        Map<Module, List<Hit>> changed = rf.findAllReferences(module, file.getProject(), null, reportDebugInformation);
        final Set<Module> modules = new HashSet<Module>();
        modules.add(module);
        modules.addAll(changed.keySet());
        reanalyseAstAfterRefactoring(file.getProject(), modules);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) TextSelection(org.eclipse.jface.text.TextSelection) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) ReferenceFinder(org.eclipse.titan.designer.AST.ReferenceFinder) List(java.util.List) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) HashSet(java.util.HashSet)

Example 88 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.

the class ProjectSourceParser method internalDoAnalyzeWithReferences.

/**
 * Internal function.
 * <p>
 * Builds the walking order of the projects from their referencing
 * graph, and analyzes all found to be related to the actual.
 *
 * @param monitor
 *                the progress monitor to provide feedback to the user
 *                about the progress.
 *
 * @return status information on exit.
 */
private IStatus internalDoAnalyzeWithReferences(final SubMonitor monitor) {
    MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SEMANTIC_MARKER, project);
    if (!checkConfigurationRequirements(project, GeneralConstants.ONTHEFLY_SEMANTIC_MARKER)) {
        MarkerHandler.removeMarkedMarkers(GeneralConstants.ONTHEFLY_SEMANTIC_MARKER, project);
        return Status.OK_STATUS;
    }
    MarkerHandler.removeMarkedMarkers(GeneralConstants.ONTHEFLY_SEMANTIC_MARKER, project);
    if (OutOfMemoryCheck.isOutOfMemoryAlreadyReported()) {
        return Status.CANCEL_STATUS;
    }
    List<IProject> tobeAnalyzed = ProjectBasedBuilder.getProjectBasedBuilder(project).getAllReachableProjects();
    // collect the projects referencing the just now analyzed
    // projects in a bottom up order into the list "tobeAnalyzed"
    Deque<IProject> temporalList = new LinkedList<IProject>();
    temporalList.addLast(project);
    tobeAnalyzed.remove(project);
    while (!temporalList.isEmpty()) {
        IProject tempProject = temporalList.getFirst();
        temporalList.removeFirst();
        if (!tobeAnalyzed.contains(tempProject)) {
            tobeAnalyzed.add(tempProject);
            IProject[] tempProjects = ProjectBasedBuilder.getProjectBasedBuilder(tempProject).getReferencingProjects();
            for (IProject tempProject2 : tempProjects) {
                if (!GlobalParser.getProjectSourceParser(tempProject2).analyzesRunning) {
                    if (tempProject2.isAccessible()) {
                        temporalList.addLast(tempProject2);
                    } else {
                        Location location = new Location(project);
                        location.reportExternalProblem(MessageFormat.format("The project {0} is not accessible but requires to analyze the project {1}", tempProject2.getName(), tempProject.getName()), IMarker.SEVERITY_ERROR, GeneralConstants.ONTHEFLY_SEMANTIC_MARKER);
                    }
                }
            }
        }
    }
    // Collect those projects that might be needed to do the correct
    // analysis.
    List<IProject> additionalRequired = new ArrayList<IProject>();
    for (IProject project : tobeAnalyzed) {
        List<IProject> temp = ProjectBasedBuilder.getProjectBasedBuilder(project).getAllReachableProjects();
        for (IProject temp2 : temp) {
            if (!tobeAnalyzed.contains(temp2) && !additionalRequired.contains(temp2) && GlobalParser.getProjectSourceParser(temp2).getLastTimeChecked() == null) {
                if (temp2.isAccessible()) {
                    additionalRequired.add(temp2);
                } else {
                    Location location = new Location(project);
                    location.reportExternalProblem(MessageFormat.format(REQUIREDPROJECTNOTACCESSIBLE, temp2.getName(), project.getName()), IMarker.SEVERITY_ERROR, GeneralConstants.ONTHEFLY_SEMANTIC_MARKER);
                }
            }
        }
    }
    tobeAnalyzed.addAll(additionalRequired);
    // Do the analyzes in the determined order.
    CompilationTimeStamp compilationCounter = CompilationTimeStamp.getNewCompilationCounter();
    SubMonitor progress = SubMonitor.convert(monitor, tobeAnalyzed.size() * 2);
    progress.setTaskName("Analysis of projects");
    IPreferencesService preferenceService = Platform.getPreferencesService();
    boolean reportDebugInformation = preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    if (reportDebugInformation) {
        TITANDebugConsole.println("On-the-fly analyzation of project " + project.getName() + " started");
    }
    List<IProject> tobeSemanticallyAnalyzed = new ArrayList<IProject>();
    try {
        for (int i = 0; i < tobeAnalyzed.size(); i++) {
            progress.subTask("Analyzing project " + tobeAnalyzed.get(i).getName());
            GlobalParser.getProjectSourceParser(tobeAnalyzed.get(i)).analyzesRunning = true;
            if (tobeAnalyzed.get(i).isAccessible()) {
                if (TITANNature.hasTITANNature(tobeAnalyzed.get(i))) {
                    GlobalParser.getProjectSourceParser(tobeAnalyzed.get(i)).syntacticAnalyzer.internalDoAnalyzeSyntactically(progress.newChild(1));
                    tobeSemanticallyAnalyzed.add(tobeAnalyzed.get(i));
                } else {
                    Location location = new Location(project, 0, 0, 0);
                    location.reportExternalProblem(MessageFormat.format(REQUIREDPROJECTNOTTITANPROJECT, tobeAnalyzed.get(i).getName(), project.getName()), IMarker.SEVERITY_ERROR, GeneralConstants.ONTHEFLY_SEMANTIC_MARKER);
                    progress.worked(1);
                }
            } else {
                Location location = new Location(project);
                location.reportExternalProblem(MessageFormat.format(REQUIREDPROJECTNOTACCESSIBLE, tobeAnalyzed.get(i).getName(), project.getName()), IMarker.SEVERITY_ERROR, GeneralConstants.ONTHEFLY_SEMANTIC_MARKER);
                progress.worked(1);
            }
        }
        ProjectSourceSemanticAnalyzer.analyzeMultipleProjectsSemantically(tobeSemanticallyAnalyzed, progress.newChild(tobeAnalyzed.size()), compilationCounter);
    // semantic check for config file
    // GlobalParser.getConfigSourceParser(project).doSemanticCheck();
    } finally {
        for (int i = 0; i < tobeAnalyzed.size(); i++) {
            GlobalParser.getProjectSourceParser(tobeAnalyzed.get(i)).analyzesRunning = false;
        }
    }
    progress.done();
    lastTimeChecked = compilationCounter;
    return Status.OK_STATUS;
}
Also used : ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) LinkedList(java.util.LinkedList) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) Location(org.eclipse.titan.designer.AST.Location)

Example 89 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.

the class ProjectSourceParser method analyzeAll.

/**
 * Analyzes all of the files which are in the project.
 * <ul>
 * <li>the files possibly needed to analyze are collected first
 * <li>those files, which are known to be up-to-date are filtered from
 * this list
 * <li>the files left in the list are analyzed in a new workspace job
 * </ul>
 *
 * @param allowQuickExit
 *                if set to true and there is an analysis going on
 *                already for the same project, the new analysis will
 *                quit immediately.
 * @return the WorkspaceJob in which the operation is running
 */
public WorkspaceJob analyzeAll(final boolean allowQuickExit) {
    IPreferencesService prefs = Platform.getPreferencesService();
    if (!prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
        return null;
    }
    WorkspaceJob configAnalyzes = GlobalParser.getConfigSourceParser(project).doSyntaticalAnalyze();
    WorkspaceJob analyzes = new WorkspaceJob(SOURCE_ANALYSING) {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) {
            IStatus result = Status.OK_STATUS;
            if (!project.isAccessible() || !TITANNature.hasTITANNature(project)) {
                return Status.CANCEL_STATUS;
            }
            if (!LicenseValidator.check()) {
                return Status.CANCEL_STATUS;
            }
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final int priority = getThread().getPriority();
            try {
                getThread().setPriority(Thread.MIN_PRIORITY);
                long absoluteStart = System.nanoTime();
                IPreferencesService preferenceService = Platform.getPreferencesService();
                String compilerOption = preferenceService.getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.COMPILERMARKERSAFTERANALYZATION, PreferenceConstantValues.COMPILEROPTIONOUTDATE, null);
                if (PreferenceConstantValues.COMPILEROPTIONREMOVE.equals(compilerOption)) {
                    ParserMarkerSupport.removeAllCompilerMarkers(project);
                } else if (PreferenceConstantValues.COMPILEROPTIONOUTDATE.equals(compilerOption)) {
                    for (Iterator<IFile> iterator = EditorTracker.keyset().iterator(); iterator.hasNext(); ) {
                        IFile file = iterator.next();
                        if (file.getProject() == project) {
                            List<ISemanticTITANEditor> editors = EditorTracker.getEditor(file);
                            if (editors != null && !editors.isEmpty()) {
                                ISemanticTITANEditor editor = editors.get(0);
                                MarkerHandler.deprecateMarkers(editor, ParserMarkerSupport.getAllCompilerMarkers(project));
                            }
                        }
                    }
                }
                result = internalDoAnalyzeWithReferences(SubMonitor.convert(monitor));
                boolean reportDebugInformation = preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
                if (reportDebugInformation) {
                    // MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream(); //used only once
                    TITANDebugConsole.println("The whole analysis block took " + (System.nanoTime() - absoluteStart) * (1e-9) + " seconds to complete");
                }
            } catch (Exception e) {
                ErrorReporter.logExceptionStackTrace(e);
            } finally {
                getThread().setPriority(priority);
            }
            return result;
        }
    };
    analyzes.setPriority(Job.LONG);
    IPreferencesService preferenceService = Platform.getPreferencesService();
    if (GeneralConstants.DEBUG && preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
        analyzes.setSystem(false);
        analyzes.setUser(true);
    } else {
        analyzes.setSystem(true);
        analyzes.setUser(false);
    }
    analyzes.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
    final ISchedulingRule rule = getSchedulingRule();
    analyzes.setRule(rule);
    if (fullAnalyzersRunning.get() > 0) {
        if (lastFullAnalyzes != null && lastFullAnalyzes.getState() != Job.RUNNING) {
            lastFullAnalyzes.cancel();
        }
        lastFullAnalyzes = analyzes;
    }
    analyzes.schedule();
    fullAnalyzersRunning.incrementAndGet();
    final WorkspaceJob temp = analyzes;
    final WorkspaceJob temp2 = configAnalyzes;
    WorkspaceJob extensions = new WorkspaceJob("Executing Titan extensions") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) {
            final SubMonitor progress = SubMonitor.convert(monitor, 100);
            final int priortity = getThread().getPriority();
            try {
                getThread().setPriority(Thread.MIN_PRIORITY);
                progress.setTaskName("Executing Titan extensions");
                progress.subTask("Waiting for semantic analysis");
                try {
                    temp.join();
                    temp2.join();
                } catch (Exception e) {
                    ErrorReporter.logExceptionStackTrace(e);
                }
                progress.subTask("Executing extensions");
                if (Status.OK_STATUS.equals(temp.getResult())) {
                    ExtensionHandler.INSTANCE.executeContributors(progress.newChild(100), project);
                }
            } finally {
                progress.done();
                fullAnalyzersRunning.decrementAndGet();
                getThread().setPriority(priortity);
            }
            return Status.OK_STATUS;
        }
    };
    if (GeneralConstants.DEBUG && preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
        extensions.setSystem(false);
        extensions.setUser(true);
    } else {
        extensions.setSystem(true);
        extensions.setUser(false);
    }
    extensions.setRule(rule);
    extensions.schedule();
    return extensions;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) SubMonitor(org.eclipse.core.runtime.SubMonitor) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) CoreException(org.eclipse.core.runtime.CoreException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ISemanticTITANEditor(org.eclipse.titan.designer.editors.ISemanticTITANEditor)

Example 90 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.

the class ProjectSourceParser method reportOutdating.

/**
 * Reports that the provided file has changed and so it's stored
 * information became out of date.
 * <p>
 * Stores that this file is out of date for later
 * <p>
 *
 * @param outdatedFile
 *                the file which seems to have changed
 *
 * @return the WorkspaceJob in which the operation is running
 */
public WorkspaceJob reportOutdating(final IFile outdatedFile) {
    WorkspaceJob op = new WorkspaceJob("Reporting outdate for: " + outdatedFile.getName()) {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) {
            syntacticAnalyzer.reportOutdating(outdatedFile);
            semanticAnalyzer.reportSemanticOutdating(outdatedFile);
            return Status.OK_STATUS;
        }
    };
    op.setPriority(Job.SHORT);
    IPreferencesService preferenceService = Platform.getPreferencesService();
    if (GeneralConstants.DEBUG && preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
        op.setSystem(false);
        op.setUser(true);
    } else {
        op.setSystem(true);
        op.setUser(false);
    }
    op.setRule(outdatedFile);
    op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
    op.schedule();
    return op;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Aggregations

IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)96 IFile (org.eclipse.core.resources.IFile)26 ArrayList (java.util.ArrayList)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)14 IProject (org.eclipse.core.resources.IProject)13 CoreException (org.eclipse.core.runtime.CoreException)13 Module (org.eclipse.titan.designer.AST.Module)11 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)11 List (java.util.List)10 File (java.io.File)8 TextSelection (org.eclipse.jface.text.TextSelection)8 Path (org.eclipse.core.runtime.Path)6 IContainer (org.eclipse.core.resources.IContainer)5 IMarker (org.eclipse.core.resources.IMarker)5 IPath (org.eclipse.core.runtime.IPath)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)5 IOException (java.io.IOException)4 IStatus (org.eclipse.core.runtime.IStatus)4