In what context? If you are inside an action, you can simply take everything from the ActionEvent, for example:
e.getData(LangDataKeys.EDITOR).getDocument().getText();
(When e is AnActionEvent).
Otherwise, you can get it from the project:
FileEditorManager.getInstance(project).getSelectedTextEditor().getDocument().getText();