Search in sources :

Example 1 with CfgParseResult

use of org.eclipse.titan.common.parsers.cfg.CfgParseResult in project titan.EclipsePlug-ins by eclipse.

the class ProjectConfigurationParser method fileBasedAnalysis.

/**
 * Parses the provided file.
 *
 * @param file (in) the file to be parsed
 * @param aMacros (in/out) collected macro references
 * @param aFilesChecked files, which are already processed (there are no duplicates)
 * @param aFilesToCheck files, which will be processed (there are no duplicates)
 */
private void fileBasedAnalysis(final IFile file, final List<Macro> aMacros, final List<IFile> aFilesToCheck, final List<IFile> aFilesChecked) {
    List<TITANMarker> warnings = null;
    List<SyntacticErrorStorage> errorsStored = null;
    IDocument document = null;
    ISemanticTITANEditor tempEditor = null;
    List<ISemanticTITANEditor> editors = null;
    if (EditorTracker.containsKey(file)) {
        editors = EditorTracker.getEditor(file);
        tempEditor = editors.get(0);
        document = tempEditor.getDocument();
    }
    ConfigTextEditor editor = null;
    if (tempEditor instanceof ConfigTextEditor) {
        editor = (ConfigTextEditor) tempEditor;
    }
    String oldConfigFilePath = fileMap.get(file);
    if (oldConfigFilePath != null) {
        fileMap.remove(file);
    }
    CfgAnalyzer cfgAnalyzer = new CfgAnalyzer();
    cfgAnalyzer.parse(file, document == null ? null : document.get());
    errorsStored = cfgAnalyzer.getErrorStorage();
    final CfgParseResult cfgParseResult = cfgAnalyzer.getCfgParseResult();
    if (cfgParseResult != null) {
        warnings = cfgParseResult.getWarnings();
        aMacros.addAll(cfgParseResult.getMacros());
        definitions.putAll(cfgParseResult.getDefinitions());
        // add included files to the aFilesToCheck list
        final List<String> includeFilenames = cfgParseResult.getIncludeFiles();
        for (final String includeFilename : includeFilenames) {
            // example value: includeFilename == MyExample2.cfg
            // example value: file == L/hw/src/MyExample.cfg
            final IPath includeFilePath = PathConverter.getProjectRelativePath(file, includeFilename);
            // example value: includeFilePath == src/MyExample2.cfg
            if (includeFilePath != null) {
                final IFile includeFile = project.getFile(includeFilePath);
                // includeFile is null if the file does not exist in the project
                if (includeFile != null && !uptodateFiles.containsKey(includeFile) && !aFilesChecked.contains(includeFile) && !aFilesToCheck.contains(includeFile)) {
                    removeMarkersAndDefinitions(includeFile);
                    aFilesToCheck.add(includeFile);
                }
            }
        }
        if (editor != null && editor.getDocument() != null) {
            ConfigEditor parentEditor = editor.getParentEditor();
            if (errorsStored == null || errorsStored.isEmpty()) {
                parentEditor.setParseTreeRoot(cfgParseResult.getParseTreeRoot());
                parentEditor.setTokens(cfgParseResult.getTokens());
                parentEditor.refresh(cfgAnalyzer);
                parentEditor.setErrorMessage(null);
            } else {
                if (errorsStored.size() > 1) {
                    parentEditor.setErrorMessage("There were " + errorsStored.size() + " problems found while parsing");
                } else {
                    parentEditor.setErrorMessage("There was 1 problem found while parsing");
                }
            }
        }
    }
    fileMap.put(file, file.getFullPath().toOSString());
    uptodateFiles.put(file, file.getFullPath().toOSString());
    if (document != null) {
        GlobalIntervalHandler.putInterval(document, cfgAnalyzer.getRootInterval());
    }
    if (warnings != null) {
        for (TITANMarker marker : warnings) {
            if (file.isAccessible()) {
                Location location = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
                location.reportExternalProblem(marker.getMessage(), marker.getSeverity(), GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
            }
        }
    }
    if (errorsStored != null && !errorsStored.isEmpty()) {
        String reportLevel = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTERRORSINEXTENSIONSYNTAX, GeneralConstants.WARNING, null);
        int errorLevel;
        if (GeneralConstants.ERROR.equals(reportLevel)) {
            errorLevel = IMarker.SEVERITY_ERROR;
        } else if (GeneralConstants.WARNING.equals(reportLevel)) {
            errorLevel = IMarker.SEVERITY_WARNING;
        } else {
            return;
        }
        for (int i = 0; i < errorsStored.size(); i++) {
            ParserMarkerSupport.createOnTheFlySyntacticMarker(file, errorsStored.get(i), errorLevel);
        }
    }
    if (document != null && editors != null) {
        ConfigFoldingSupport foldingSupport = new ConfigFoldingSupport();
        final IDocument tempDocument = document;
        final List<ISemanticTITANEditor> editors2 = editors;
        final List<Position> positions = foldingSupport.calculatePositions(tempDocument);
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                for (ISemanticTITANEditor editor : editors2) {
                    editor.updateFoldingStructure(positions);
                    editor.invalidateTextPresentation();
                }
            }
        });
    }
}
Also used : CfgParseResult(org.eclipse.titan.common.parsers.cfg.CfgParseResult) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Position(org.eclipse.jface.text.Position) ConfigTextEditor(org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor) ConfigEditor(org.eclipse.titan.designer.editors.configeditor.ConfigEditor) ConfigFoldingSupport(org.eclipse.titan.designer.editors.configeditor.ConfigFoldingSupport) TITANMarker(org.eclipse.titan.common.parsers.TITANMarker) SyntacticErrorStorage(org.eclipse.titan.common.parsers.SyntacticErrorStorage) CfgAnalyzer(org.eclipse.titan.common.parsers.cfg.CfgAnalyzer) ISemanticTITANEditor(org.eclipse.titan.designer.editors.ISemanticTITANEditor) IDocument(org.eclipse.jface.text.IDocument) CfgLocation(org.eclipse.titan.common.parsers.cfg.CfgLocation) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 IDocument (org.eclipse.jface.text.IDocument)1 Position (org.eclipse.jface.text.Position)1 SyntacticErrorStorage (org.eclipse.titan.common.parsers.SyntacticErrorStorage)1 TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)1 CfgAnalyzer (org.eclipse.titan.common.parsers.cfg.CfgAnalyzer)1 CfgLocation (org.eclipse.titan.common.parsers.cfg.CfgLocation)1 CfgParseResult (org.eclipse.titan.common.parsers.cfg.CfgParseResult)1 Location (org.eclipse.titan.designer.AST.Location)1 ISemanticTITANEditor (org.eclipse.titan.designer.editors.ISemanticTITANEditor)1 ConfigEditor (org.eclipse.titan.designer.editors.configeditor.ConfigEditor)1 ConfigFoldingSupport (org.eclipse.titan.designer.editors.configeditor.ConfigFoldingSupport)1 ConfigTextEditor (org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor)1