Search in sources :

Example 1 with ASN1Editor

use of org.eclipse.titan.designer.editors.asn1editor.ASN1Editor 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 ASN1Editor) {
        this.targetEditor = (ASN1Editor) activeEditor;
    } else {
        this.targetEditor = null;
    }
    if (activeEditor == null) {
        return null;
    }
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                return null;
            }
        }
    }
    IDocument document = this.targetEditor.getDocument();
    int carretOffset = this.targetEditor.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;
    }
    this.targetEditor.setCarretOffset(targetOffset);
    this.targetEditor.selectAndReveal(targetOffset, 0);
    return null;
}
Also used : ASN1Editor(org.eclipse.titan.designer.editors.asn1editor.ASN1Editor) PairMatcher(org.eclipse.titan.designer.editors.asn1editor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with ASN1Editor

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

TextSelection (org.eclipse.jface.text.TextSelection)2 ASN1Editor (org.eclipse.titan.designer.editors.asn1editor.ASN1Editor)2 IFile (org.eclipse.core.resources.IFile)1 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 Module (org.eclipse.titan.designer.AST.Module)1 Declaration (org.eclipse.titan.designer.declarationsearch.Declaration)1 IdentifierFinderVisitor (org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor)1 PairMatcher (org.eclipse.titan.designer.editors.asn1editor.PairMatcher)1 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)1 IEditorPart (org.eclipse.ui.IEditorPart)1