use of com.intellij.openapi.application.RunResult in project intellij-community by JetBrains.
the class AddWithParamFix method invoke.
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException {
final RunResult<SmartPsiElementPointer<XmlTag>> result = new WriteAction<SmartPsiElementPointer<XmlTag>>() {
protected void run(@NotNull Result<SmartPsiElementPointer<XmlTag>> result) throws Throwable {
final XmlTag withParamTag = RefactoringUtil.addWithParam(myTag);
withParamTag.setAttribute("name", myName != null ? myName : "dummy");
withParamTag.setAttribute("select", "dummy");
result.setResult(SmartPointerManager.getInstance(project).createSmartPsiElementPointer(withParamTag));
}
}.execute();
final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
final Document doc = psiDocumentManager.getDocument(file);
assert doc != null;
psiDocumentManager.doPostponedOperationsAndUnblockDocument(doc);
final XmlTag withParamTag = result.getResultObject().getElement();
assert withParamTag != null;
final TemplateBuilderImpl builder = new TemplateBuilderImpl(withParamTag);
final XmlAttribute selectAttr = withParamTag.getAttribute("select", null);
assert selectAttr != null;
PsiElement dummy = XsltSupport.getAttValueToken(selectAttr);
builder.replaceElement(dummy, new MacroCallNode(new CompleteMacro()));
if (myName == null) {
final XmlAttribute nameAttr = withParamTag.getAttribute("name", null);
assert nameAttr != null;
dummy = XsltSupport.getAttValueToken(nameAttr);
builder.replaceElement(dummy, new MacroCallNode(new CompleteMacro()));
}
moveTo(editor, withParamTag);
new WriteAction() {
@SuppressWarnings({ "RawUseOfParameterizedType" })
protected void run(@NotNull Result result) throws Throwable {
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
final TemplateManager mgr = TemplateManager.getInstance(myTag.getProject());
mgr.startTemplate(editor, builder.buildInlineTemplate());
}
}.execute();
}
Aggregations