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;
}
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();
}
}
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());
}
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;
}
Aggregations