PrepopulatedCollectionModel (PsiAnonymousClass anonymousClass, String type, CallMatcher addMethod) { PsiClassInitializer initializer = ClassUtils.getDoubleBraceInitializer(anonymousClass); if(initializer != null) { List<PsiExpression> contents = new ArrayList<>(); for(PsiStatement statement : initializer.getBody().getStatements()) { if(!(statement instanceof PsiExpressionStatement)) return null; PsiMethodCallExpression call = tryCast(((PsiExpressionStatement)statement).getExpression(), PsiMethodCallExpression.class); if(!addMethod.test(call)) return null; PsiExpression qualifier = call.getMethodExpression().getQualifierExpression(); if(qualifier != null && !qualifier.getText().equals("this")) return null; contents.addAll(Arrays.asList(call.getArgumentList().getExpressions())); } return new PrepopulatedCollectionModel(contents, Collections.emptyList(), type); } return null; }