Search in sources :

Example 6 with ErlToken

use of org.erlide.engine.services.parsing.ErlToken in project erlide_eclipse by erlang.

the class ErlangBracketInserter method getKindOfBracket.

private int getKindOfBracket(final IDocument document, final int offset, final int length) throws BadLocationException {
    final IRegion endLine = document.getLineInformationOfOffset(offset + length);
    List<ErlToken> tokens = null;
    final int getOffset = offset + length;
    final int getLength = endLine.getOffset() + endLine.getLength() - getOffset;
    final String str = document.get(getOffset, getLength);
    try {
        tokens = ErlangEngine.getInstance().getSimpleScannerService().lightScanString(str, 0);
    } catch (final ScannerException e) {
    }
    int kind = ErlToken.KIND_OTHER;
    if (tokens != null && !tokens.isEmpty()) {
        kind = tokens.get(0).getKind();
    } else if (!str.isEmpty()) {
        kind = str.charAt(0);
    }
    return kind;
}
Also used : ScannerException(org.erlide.engine.services.parsing.ScannerException) ErlToken(org.erlide.engine.services.parsing.ErlToken) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point)

Example 7 with ErlToken

use of org.erlide.engine.services.parsing.ErlToken in project erlide_eclipse by erlang.

the class IErlModuleTest method getScannerTokenAt.

// ErlToken getScannerTokenAt(int offset);
@Test
public void getScannerTokenAt() throws Exception {
    final ScannerService scanner = module.getScanner();
    try {
        module.open(null);
        final ErlToken token = scanner.getTokenAt(-1);
        final ErlToken token2 = scanner.getTokenAt(0);
        final ErlToken token3 = scanner.getTokenAt(1);
        final ErlToken token4 = scanner.getTokenAt(10);
        final ErlToken token5 = scanner.getTokenAt(24);
        final ErlToken token6 = scanner.getTokenAt(61);
        final ErlToken token7 = scanner.getTokenAt(62);
        assertNull(token);
        assertNotNull(token2);
        assertEquals(ErlToken.KIND_OTHER, token2.getKind());
        assertNotNull(token3);
        assertEquals(ErlToken.KIND_ATOM, token3.getKind());
        assertNotNull(token4);
        assertEquals(ErlToken.KIND_OTHER, token4.getKind());
        assertNotNull(token5);
        assertEquals(ErlToken.KIND_STRING, token5.getKind());
        assertNotNull(token6);
        assertEquals(ErlToken.KIND_OTHER, token6.getKind());
        assertNull(token7);
    } finally {
        scanner.dispose();
    }
}
Also used : ErlToken(org.erlide.engine.services.parsing.ErlToken) ScannerService(org.erlide.engine.services.parsing.ScannerService) Test(org.junit.Test)

Example 8 with ErlToken

use of org.erlide.engine.services.parsing.ErlToken in project erlide_eclipse by erlang.

the class ErlTextHover method internalGetHoverRegion.

private static IRegion internalGetHoverRegion(final int offset, final AbstractErlangEditor editor) {
    if (editor == null) {
        return null;
    }
    editor.reconcileNow();
    final ErlToken token = editor.getScanner().getTokenAt(offset);
    if (token == null) {
        return null;
    }
    return new Region(token.getOffset(), token.getLength());
}
Also used : IRegion(org.eclipse.jface.text.IRegion) Region(org.eclipse.jface.text.Region) ErlToken(org.erlide.engine.services.parsing.ErlToken)

Example 9 with ErlToken

use of org.erlide.engine.services.parsing.ErlToken in project erlide_eclipse by erlang.

the class ConvertMultiStringQuickFix method appliesAt.

@Override
public boolean appliesAt(final IQuickAssistInvocationContext invocationContext) {
    final ISourceViewer viewer = invocationContext.getSourceViewer();
    final IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (!(editorPart instanceof ErlangEditor)) {
        return false;
    }
    final ErlangEditor editor = (ErlangEditor) editorPart;
    if (editor.getViewer() != viewer) {
        return false;
    }
    final IErlModule module = editor.getModule();
    final int offset = invocationContext.getOffset();
    final ErlToken token = module.getScanner().getTokenAt(offset);
    if (token == null || token.getKind() != ErlToken.KIND_STRING) {
        return false;
    }
    final IDocument doc = viewer.getDocument();
    String text;
    try {
        text = doc.get(token.getOffset(), token.getLength());
        if (text.contains("\n")) {
            return true;
        }
    } catch (final BadLocationException e) {
    }
    return false;
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) IEditorPart(org.eclipse.ui.IEditorPart) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ErlToken(org.erlide.engine.services.parsing.ErlToken) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor)

Aggregations

ErlToken (org.erlide.engine.services.parsing.ErlToken)9 IRegion (org.eclipse.jface.text.IRegion)3 ScannerException (org.erlide.engine.services.parsing.ScannerException)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Region (org.eclipse.jface.text.Region)2 RpcException (org.erlide.runtime.rpc.RpcException)2 RpcTimeoutException (org.erlide.runtime.rpc.RpcTimeoutException)2 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)1 IDocument (org.eclipse.jface.text.IDocument)1 ITypedRegion (org.eclipse.jface.text.ITypedRegion)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 Point (org.eclipse.swt.graphics.Point)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IErlModule (org.erlide.engine.model.root.IErlModule)1 ScannerService (org.erlide.engine.services.parsing.ScannerService)1 AbstractErlangEditor (org.erlide.ui.editors.erl.AbstractErlangEditor)1 ErlangEditor (org.erlide.ui.editors.erl.ErlangEditor)1