Search in sources :

Example 1 with ConfigEditor

use of org.eclipse.titan.designer.editors.configeditor.ConfigEditor in project titan.EclipsePlug-ins by eclipse.

the class GotoMatchingBracketAction method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof ConfigEditor) {
        this.targetEditor = (ConfigEditor) activeEditor;
    } else {
        this.targetEditor = null;
    }
    if (activeEditor == null) {
        return null;
    }
    if (this.targetEditor.getActiveEditor() != this.targetEditor.getEditor()) {
        return null;
    }
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                return null;
            }
        }
    }
    ConfigTextEditor textEditor = this.targetEditor.getEditor();
    IDocument document = textEditor.getDocument();
    int carretOffset = textEditor.getCarretOffset();
    PairMatcher pairMatcher = new PairMatcher();
    IRegion region = pairMatcher.match(document, carretOffset);
    if (region == null) {
        return null;
    }
    int targetOffset;
    if (region.getOffset() + 1 == carretOffset) {
        targetOffset = region.getOffset() + region.getLength();
    } else {
        targetOffset = region.getOffset() + 1;
    }
    textEditor.setCarretOffset(targetOffset);
    textEditor.selectAndReveal(targetOffset, 0);
    return null;
}
Also used : PairMatcher(org.eclipse.titan.designer.editors.configeditor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) ConfigEditor(org.eclipse.titan.designer.editors.configeditor.ConfigEditor) ConfigTextEditor(org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with ConfigEditor

use of org.eclipse.titan.designer.editors.configeditor.ConfigEditor 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 3 with ConfigEditor

use of org.eclipse.titan.designer.editors.configeditor.ConfigEditor 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 4 with ConfigEditor

use of org.eclipse.titan.designer.editors.configeditor.ConfigEditor in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method selectAndRevealRegion.

/**
 * Opens an editor for the provided declaration, and in this editor the
 * location of the declaration is revealed and highlighted.
 *
 * @param file
 *                The file to open.
 * @param offset
 *                The start position of the declaration to select.
 * @param endOffset
 *                The end position of the declaration to select.
 * @param select
 *                Select the given region if true.
 */
private void selectAndRevealRegion(final IFile file, final int offset, final int endOffset, final boolean select) {
    IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
    if (desc == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(EDITORNOTFOUND);
        return;
    }
    if (!select) {
        return;
    }
    try {
        IWorkbenchPage page = targetEditor.getSite().getPage();
        IEditorPart editorPart = page.openEditor(new FileEditorInput(file), desc.getId());
        if (editorPart != null) {
            // not AbstractTextEditor.
            if (editorPart instanceof ConfigEditor) {
                ((AbstractTextEditor) ((ConfigEditor) editorPart).getEditor()).selectAndReveal(offset, endOffset - offset);
            } else if (editorPart instanceof AbstractTextEditor) {
                ((AbstractTextEditor) editorPart).selectAndReveal(offset, endOffset - offset);
            }
        }
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ConfigEditor(org.eclipse.titan.designer.editors.configeditor.ConfigEditor) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 5 with ConfigEditor

use of org.eclipse.titan.designer.editors.configeditor.ConfigEditor 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

ConfigEditor (org.eclipse.titan.designer.editors.configeditor.ConfigEditor)5 IDocument (org.eclipse.jface.text.IDocument)4 ConfigTextEditor (org.eclipse.titan.designer.editors.configeditor.ConfigTextEditor)4 IFile (org.eclipse.core.resources.IFile)3 TextSelection (org.eclipse.jface.text.TextSelection)3 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)2 CfgInterval.section_type (org.eclipse.titan.common.parsers.cfg.CfgInterval.section_type)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IPath (org.eclipse.core.runtime.IPath)1 IRegion (org.eclipse.jface.text.IRegion)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 ConfigFoldingSupport (org.eclipse.titan.designer.editors.configeditor.ConfigFoldingSupport)1 PairMatcher (org.eclipse.titan.designer.editors.configeditor.PairMatcher)1