boolean (@Nullable String text, boolean afterDot, Project project) { if (text == null) return false; try { GroovyPsiElementFactory.getInstance(project).createReferenceExpressionFromText(afterDot ? "foo." + text : text); return true; } catch (Exception e) { return false; } }