void (PsiClass innerClass) { PsiNewExpression newExpr = (PsiNewExpression) myAnonOrLocalClass.getParent(); @NonNls StringBuilder buf = new StringBuilder(); buf.append("new "); buf.append(innerClass.getName()); if (!myTypeParametersToCreate.isEmpty()) { buf.append("<"); int idx = 0; for (Iterator<PsiTypeParameter> it = myTypeParametersToCreate.iterator(); it.hasNext(); idx++) { if (idx > 0) buf.append(", "); String typeParamName = it.next().getName(); buf.append(typeParamName); } buf.append(">"); } buf.append("("); boolean isFirstParameter = true; for (VariableInfo info : myVariableInfos) { if (info.passAsParameter) { if (isFirstParameter) { isFirstParameter = false; } else { buf.append(","); } buf.append(info.variable.getName()); } } buf.append(")"); PsiNewExpression newClassExpression = (PsiNewExpression)JavaPsiFacade.getElementFactory(myManager.getProject()).createExpressionFromText(buf.toString(), null); newExpr.replace(newClassExpression); }