PsiElement (@NotNull String refName) { GroovyFileBase file = createGroovyFileChecked("a." + refName); GrTopStatement statement = file.getTopStatements()[0]; if (!(statement instanceof GrReferenceExpression)) { throw new IncorrectOperationException("Incorrect reference name: " + refName); } final PsiElement element = ((GrReferenceExpression)statement).getReferenceNameElement(); if (element == null) { throw new IncorrectOperationException("Incorrect reference name: " + refName); } return element; }