Search in sources :

Example 31 with IPreferencesService

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

the class ProjectSourceSyntacticAnalyzer method reportOutdating.

/**
 * Reports that the contents of the provided folder has changed and so
 * it's stored information became out of date.
 * <p>
 * Stores that every file in this folder is out of date for later
 * <p>
 *
 * @param outdatedFolder
 *                the folder whose files seems to have changed
 */
public void reportOutdating(final IFolder outdatedFolder) {
    final IPath folderPath = outdatedFolder.getProjectRelativePath();
    final IPreferencesService service = Platform.getPreferencesService();
    final boolean useOnTheFlyParsing = service.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null);
    synchronized (this) {
        syntacticallyOutdated = true;
        for (Iterator<IFile> iterator = uptodateFiles.keySet().iterator(); iterator.hasNext(); ) {
            IFile tempFile = iterator.next();
            IPath filepath = tempFile.getProjectRelativePath();
            if (folderPath.isPrefixOf(filepath)) {
                sourceParser.getSemanticAnalyzer().reportOutdating(tempFile, useOnTheFlyParsing);
                iterator.remove();
                unsupportedConstructMap.remove(tempFile);
            }
        }
        for (Iterator<IFile> iterator = highlySyntaxErroneousFiles.iterator(); iterator.hasNext(); ) {
            IFile tempFile = iterator.next();
            IPath filepath = tempFile.getProjectRelativePath();
            if (folderPath.isPrefixOf(filepath)) {
                iterator.remove();
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 32 with IPreferencesService

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

the class ProjectSourceSyntacticAnalyzer 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 usage
 * <p>
 *
 * @param outdatedFile
 *                the file which seems to have changed
 */
public void reportOutdating(final IFile outdatedFile) {
    final IPreferencesService service = Platform.getPreferencesService();
    final boolean useOnTheFlyParsing = service.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null);
    synchronized (this) {
        syntacticallyOutdated = true;
        if (uptodateFiles.containsKey(outdatedFile)) {
            uptodateFiles.remove(outdatedFile);
            unsupportedConstructMap.remove(outdatedFile);
        }
        if (highlySyntaxErroneousFiles.contains(outdatedFile)) {
            highlySyntaxErroneousFiles.remove(outdatedFile);
        }
        sourceParser.getSemanticAnalyzer().reportOutdating(outdatedFile, useOnTheFlyParsing);
    }
}
Also used : IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 33 with IPreferencesService

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

the class ReferenceSearch method runAction.

/**
 * Helper function used by FindReferences classes for TTCN-3, ASN.1 and
 * TTCNPP editors
 */
public static void runAction(final IEditorPart targetEditor, final ISelection selection) {
    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;
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    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.println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((IEditorWithCarretOffset) targetEditor).getCarretOffset();
    }
    // find the module
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    if (ResourceExclusionHelper.isExcluded(file)) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
        return;
    }
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(NOTFOUNDMODULE, file.getName()));
        return;
    }
    final ReferenceFinder rf = new ReferenceFinder();
    boolean isDetected = rf.detectAssignmentDataByOffset(module, offset, targetEditor, true, reportDebugInformation);
    if (!isDetected) {
        return;
    }
    final ReferenceSearchQuery query = new ReferenceSearchQuery(rf, module, file.getProject());
    for (ISearchQuery runningQuery : NewSearchUI.getQueries()) {
        NewSearchUI.cancelQuery(runningQuery);
    }
    NewSearchUI.runQueryInBackground(query);
}
Also used : IFile(org.eclipse.core.resources.IFile) ReferenceFinder(org.eclipse.titan.designer.AST.ReferenceFinder) TextSelection(org.eclipse.jface.text.TextSelection) Module(org.eclipse.titan.designer.AST.Module) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) ISearchQuery(org.eclipse.search.ui.ISearchQuery)

Example 34 with IPreferencesService

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

the class RenameRefactoring method checkInitialConditions.

@Override
public RefactoringStatus checkInitialConditions(final IProgressMonitor pm) throws CoreException {
    // for debugging
    // ScopeHierarchyVisitor v = new ScopeHierarchyVisitor();
    // module.accept(v);
    // TITANDebugConsole.getConsole().newMessageStream().println(v.getScopeTreeAsHTMLPage());
    RefactoringStatus result = new RefactoringStatus();
    try {
        pm.beginTask("Checking preconditions...", 2);
        // PreferenceConstants.USEONTHEFLYPARSING
        final IPreferencesService prefs = Platform.getPreferencesService();
        if (!prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, false, null)) {
            result.addFatalError(ONTHEFLYANALAYSISDISABLED);
        }
        // check that there are no ttcnpp files in the project
        if (hasTtcnppFiles(file.getProject())) {
            // FIXME actually all referencing and referenced projects need to be checked too !
            result.addError(MessageFormat.format(PROJECTCONTAINSTTCNPPFILES, file.getProject()));
        }
        pm.worked(1);
        // Check that there are no syntactic, semantic or mixed error markers in the project. Compilation error does not matter
        IProject project = file.getProject();
        if (projectHasOnTheFlyError(project)) {
            result.addError(MessageFormat.format(PROJECTCONTAINSERRORS, project));
        }
        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) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IProject(org.eclipse.core.resources.IProject)

Example 35 with IPreferencesService

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

the class OpenDeclaration method handleModuleParameters.

/**
 * Selects and reveals the selected module parameter.
 *
 * @param file
 *                The current file.
 * @param offset
 *                The position of the cursor.
 * @param document
 *                The document opened in the configuration file editor.
 * @return True
 */
public boolean handleModuleParameters(final IFile file, final int offset, final IDocument document) {
    ConfigReferenceParser refParser = new ConfigReferenceParser(false);
    Reference reference = refParser.findReferenceForOpening(file, offset, document);
    if (refParser.isModuleParameter()) {
        if (reference == null) {
            return false;
        }
        ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
        String exactModuleName = refParser.getExactModuleName();
        ArrayList<Assignment> foundAssignments = new ArrayList<Assignment>();
        if (exactModuleName != null) {
            Module module = projectSourceParser.getModuleByName(exactModuleName);
            if (module != null) {
                Assignments assignments = module.getAssignments();
                for (int i = 0; i < assignments.getNofAssignments(); i++) {
                    Assignment assignment = assignments.getAssignmentByIndex(i);
                    if (assignment.getIdentifier().getDisplayName().equals(reference.getId().getDisplayName())) {
                        foundAssignments.add(assignment);
                    }
                }
            }
        } else {
            for (String moduleName : projectSourceParser.getKnownModuleNames()) {
                Module module = projectSourceParser.getModuleByName(moduleName);
                if (module != null) {
                    Assignments assignments = module.getAssignments();
                    for (int i = 0; i < assignments.getNofAssignments(); i++) {
                        Assignment assignment = assignments.getAssignmentByIndex(i);
                        if (assignment.getIdentifier().getDisplayName().equals(reference.getId().getDisplayName())) {
                            foundAssignments.add(assignment);
                        }
                    }
                }
            }
        }
        if (foundAssignments.isEmpty()) {
            targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTMODULEPARDECLARATION);
            return false;
        }
        // List<DeclarationCollectionHelper> collected = declarationCollector.getCollected();
        // DeclarationCollectionHelper declaration = null;
        Assignment assignment = null;
        if (foundAssignments.size() == 1) {
            assignment = foundAssignments.get(0);
        } else {
            Assignment result = openCollectionListDialog(foundAssignments);
            if (result != null) {
                assignment = result;
            }
        }
        IPreferencesService prefs = Platform.getPreferencesService();
        if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
            for (Assignment tempAssignment : foundAssignments) {
                Location location = tempAssignment.getLocation();
                TITANDebugConsole.println("Module parameter: " + location.getFile() + ":" + location.getOffset() + "-" + location.getEndOffset());
            }
        }
        if (assignment != null) {
            Location location = assignment.getLocation();
            selectAndRevealRegion((IFile) location.getFile(), location.getOffset(), location.getEndOffset(), true);
        }
        return true;
    }
    return false;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ConfigReferenceParser(org.eclipse.titan.designer.editors.configeditor.ConfigReferenceParser) Reference(org.eclipse.titan.designer.AST.Reference) ArrayList(java.util.ArrayList) Assignments(org.eclipse.titan.designer.AST.Assignments) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) CfgLocation(org.eclipse.titan.common.parsers.cfg.CfgLocation) Location(org.eclipse.titan.designer.AST.Location)

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