PsiFile flexFile = position.getContainingFile();
Language language = flexFile.getLanguage();
String flexFileText = flexFile.getText();
int positionOffset = position.getTextRange().getEndOffset();
JFlexExpression expr = PsiTreeUtil.getParentOfType(position, JFlexExpression.class);
final boolean inMacro =
expr != null && expr.getText().substring(0, positionOffset - expr.getTextRange().getStartOffset()).indexOf('\n') == -1;
String fragment = (inDeclare ? "%%\n" : "%%\n%%\n") + flexFileText.substring(flexFileText.lastIndexOf("%%", positionOffset-1) + 2, positionOffset);
boolean empty = StringUtil.isEmptyOrSpaces(fragment);
final String text = empty ? CompletionInitializationContext.DUMMY_IDENTIFIER : fragment;
int completionOffset = empty ? 0 : fragment.length();