public static String lastWord(final IDocument doc, final int offset) { try { for (int n = offset - 1; n >= 0; n--) { final char c = doc.getChar(n); if (!Character.isJavaIdentifierPart(c)) return doc.get(n + 1, offset - n - 1); } } catch (final BadLocationException e) { GroovyPlugin.getPlugin().logException(e.getMessage(), e); } return ""; }
public static String lastIndent(final IDocument doc, final int offset) { try { int start = offset - 1; while (start >= 0 && doc.getChar(start) != '\n') start--; int end = start; while (end < offset && Character.isSpaceChar(doc.getChar(end))) end++; return doc.get(start + 1, end - start - 1); } catch (final BadLocationException e) { GroovyPlugin.getPlugin().logException(e.getMessage(), e); } return ""; }