PsiExpression (@NotNull PsiElement anonymousClass, PsiType expectedType) { PsiNewExpression newArrayExpression = (PsiNewExpression)JavaPsiFacade.getElementFactory(anonymousClass.getProject()) .createExpressionFromText("new " + expectedType.getCanonicalText() + "[]{" + anonymousClass.getText() + "}", anonymousClass); PsiArrayInitializerExpression initializer = newArrayExpression.getArrayInitializer(); LOG.assertTrue(initializer != null); return replacePsiElementWithLambda(initializer.getInitializers()[0], true, false); }