GrMethod (String methodText, @Nullable PsiElement context) { if (methodText == null) throw new IncorrectOperationException("Method text not provided"); GroovyFile file = createGroovyFile(methodText, false, context); GrTopStatement[] definitions = file.getTopStatements(); if (definitions.length != 1) { throw new IncorrectOperationException("Can't create method from text: '" + file.getText() + "'"); } GrTopStatement definition = definitions[0]; if (!(definition instanceof GrMethod)) { throw new IncorrectOperationException("Can't create method from text: '" + file.getText() + "'"); } return ((GrMethod)definition); }