use of com.intellij.codeInsight.generation.GenerationInfo in project intellij-community by JetBrains.
the class CreateFieldOrPropertyFix method generateMembers.
private void generateMembers(final Project project, final Editor editor, final PsiFile file) {
try {
List<? extends GenerationInfo> prototypes = new GenerateFieldOrPropertyHandler(myName, myType, myMemberType, myAnnotations).generateMemberPrototypes(myClass, ClassMember.EMPTY_ARRAY);
prototypes = GenerateMembersUtil.insertMembersAtOffset(myClass, editor.getCaretModel().getOffset(), prototypes);
if (prototypes.isEmpty())
return;
final PsiElement scope = prototypes.get(0).getPsiMember().getContext();
assert scope != null;
final Expression expression = new EmptyExpression() {
@Override
public com.intellij.codeInsight.template.Result calculateResult(final ExpressionContext context) {
return new TextResult(myType.getCanonicalText());
}
};
final TemplateBuilderImpl builder = new TemplateBuilderImpl(scope);
boolean first = true;
@NonNls final String TYPE_NAME_VAR = "TYPE_NAME_VAR";
for (GenerationInfo prototype : prototypes) {
final PsiTypeElement typeElement = PropertyUtil.getPropertyTypeElement(prototype.getPsiMember());
if (first) {
first = false;
builder.replaceElement(typeElement, TYPE_NAME_VAR, expression, true);
} else {
builder.replaceElement(typeElement, TYPE_NAME_VAR, TYPE_NAME_VAR, false);
}
}
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
editor.getCaretModel().moveToOffset(scope.getTextRange().getStartOffset());
TemplateManager.getInstance(project).startTemplate(editor, builder.buildInlineTemplate());
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
Aggregations