Search in sources :

Example 81 with IPreferencesService

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

the class LazyficationRefactoring method checkInitialConditions.

@Override
public RefactoringStatus checkInitialConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    final RefactoringStatus result = new RefactoringStatus();
    try {
        pm.beginTask("Checking preconditions...", 3);
        // check "use on the fly parsing", and "minimize memory usage" settings
        final IPreferencesService prefs = Platform.getPreferencesService();
        if (!prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, false, null)) {
            result.addError(ONTHEFLYANALAYSISDISABLED);
        }
        pm.worked(1);
        // check that there are no ttcnpp files in the project
        for (IProject project : projects) {
            if (hasTtcnppFiles(project)) {
                // FIXME actually all referencing and referenced projects need to be checked too !
                result.addError(MessageFormat.format(PROJECTCONTAINSTTCNPPFILES, project));
            }
        }
        pm.worked(1);
        // check that there are no error markers in the project
        for (IProject project : projects) {
            final IMarker[] markers = project.findMarkers(null, true, IResource.DEPTH_INFINITE);
            for (IMarker marker : markers) {
                if (IMarker.SEVERITY_ERROR == marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR)) {
                    result.addError(MessageFormat.format(PROJECTCONTAINSERRORS, project));
                    break;
                }
            }
        }
        pm.worked(1);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        result.addFatalError(e.getMessage());
    } finally {
        pm.done();
    }
    return result;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMarker(org.eclipse.core.resources.IMarker) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IProject(org.eclipse.core.resources.IProject)

Example 82 with IPreferencesService

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

the class OpenDeclaration method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    targetEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (targetEditor instanceof ConfigEditor) {
        targetEditor = ((ConfigEditor) targetEditor).getEditor();
    }
    if (targetEditor == null || !(targetEditor instanceof ConfigTextEditor)) {
        return null;
    }
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTIDENTIFIABLEFILE);
        return null;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return null;
    }
    int offset;
    if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
        IPreferencesService prefs = Platform.getPreferencesService();
        if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
            TITANDebugConsole.println("Selected: " + ((TextSelection) selection).getText());
        }
        TextSelection textSelection = (TextSelection) selection;
        offset = textSelection.getOffset() + textSelection.getLength();
    } else {
        offset = ((ConfigTextEditor) targetEditor).getCarretOffset();
    }
    IDocument document = ((ConfigTextEditor) targetEditor).getDocument();
    section_type section = getSection(document, offset);
    if (section_type.UNKNOWN.equals(section)) {
        if (handleModuleParameters(file, offset, document)) {
            return null;
        }
        return null;
    } else if (section_type.INCLUDE.equals(section)) {
        handleIncludes(file, offset, document);
        return null;
    } else if (section_type.MODULE_PARAMETERS.equals(section)) {
        // identifiable as a module parameter.
        if (handleModuleParameters(file, offset, document)) {
            return null;
        }
    }
    // Fall back.
    handleDefinitions(file, offset, document);
    return null;
}
Also used : CfgInterval.section_type(org.eclipse.titan.common.parsers.cfg.CfgInterval.section_type) IFile(org.eclipse.core.resources.IFile) TextSelection(org.eclipse.jface.text.TextSelection) ConfigEditor(org.eclipse.titan.designer.editors.configeditor.ConfigEditor) ConfigTextEditor(org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IDocument(org.eclipse.jface.text.IDocument)

Example 83 with IPreferencesService

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

the class OpenDeclaration method run.

@Override
public void run(final IAction action) {
    if (targetEditor instanceof ConfigEditor) {
        targetEditor = ((ConfigEditor) targetEditor).getEditor();
    }
    if (targetEditor == null || !(targetEditor instanceof ConfigTextEditor)) {
        return;
    }
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTIDENTIFIABLEFILE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    int offset;
    if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
        IPreferencesService prefs = Platform.getPreferencesService();
        if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
            TITANDebugConsole.println("Selected: " + ((TextSelection) selection).getText());
        }
        TextSelection textSelection = (TextSelection) selection;
        offset = textSelection.getOffset() + textSelection.getLength();
    } else {
        offset = ((ConfigTextEditor) targetEditor).getCarretOffset();
    }
    IDocument document = ((ConfigTextEditor) targetEditor).getDocument();
    section_type section = getSection(document, offset);
    if (section_type.UNKNOWN.equals(section)) {
        return;
    } else if (section_type.INCLUDE.equals(section)) {
        handleIncludes(file, offset, document);
        return;
    } else if (section_type.MODULE_PARAMETERS.equals(section)) {
        // identifiable as a module parameter.
        if (handleModuleParameters(file, offset, document)) {
            return;
        }
    }
    // Fall back.
    handleDefinitions(file, offset, document);
}
Also used : CfgInterval.section_type(org.eclipse.titan.common.parsers.cfg.CfgInterval.section_type) IFile(org.eclipse.core.resources.IFile) TextSelection(org.eclipse.jface.text.TextSelection) ConfigEditor(org.eclipse.titan.designer.editors.configeditor.ConfigEditor) ConfigTextEditor(org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IDocument(org.eclipse.jface.text.IDocument)

Example 84 with IPreferencesService

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

the class ReconcilingStrategy method initialReconcile.

@Override
public void initialReconcile() {
    GlobalIntervalHandler.putInterval(document, null);
    IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
        analyze();
    } else {
        Display.getDefault().asyncExec(new Runnable() {

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

Example 85 with IPreferencesService

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

the class OpenDeclaration method doOpenDeclaration.

private final void doOpenDeclaration() {
    if (targetEditor == null || !(targetEditor instanceof ASN1Editor)) {
        return;
    }
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    if (ResourceExclusionHelper.isExcluded(file)) {
        MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
        return;
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((ASN1Editor) targetEditor).getCarretOffset();
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        // TODO: How could this happen??? (NPE occured)
        return;
    }
    IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
    module.accept(visitor);
    final Declaration decl = visitor.getReferencedDeclaration();
    if (decl == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("No visible elements found");
        }
        return;
    }
    selectAndRevealDeclaration(decl.getIdentifier().getLocation());
}
Also used : ASN1Editor(org.eclipse.titan.designer.editors.asn1editor.ASN1Editor) IFile(org.eclipse.core.resources.IFile) IdentifierFinderVisitor(org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor) TextSelection(org.eclipse.jface.text.TextSelection) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration) Module(org.eclipse.titan.designer.AST.Module) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

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