private void doImport(final PsiMethod toImport) { CommandProcessor.getInstance() .executeCommand( toImport.getProject(), new Runnable() { @Override public void run() { ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { try { PsiMethodCallExpression element = myMethodCall.getElement(); if (element != null) { element .getMethodExpression() .bindToElementViaStaticImport(toImport.getContainingClass()); } } catch (IncorrectOperationException e) { LOG.error(e); } } }); } }, getText(), this); }
@Override protected PsiVariable createFieldToStartTemplateOn( final String[] names, final PsiType defaultType) { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myMethod.getProject()); return ApplicationManager.getApplication() .runWriteAction( new Computable<PsiParameter>() { @Override public PsiParameter compute() { final PsiParameter anchor = JavaIntroduceParameterMethodUsagesProcessor.getAnchorParameter(myMethod); final PsiParameter psiParameter = (PsiParameter) myMethod .getParameterList() .addAfter( elementFactory.createParameter( chooseName(names, myMethod.getLanguage()), defaultType), anchor); PsiUtil.setModifierProperty( psiParameter, PsiModifier.FINAL, myPanel.hasFinalModifier()); myParameterIndex = myMethod.getParameterList().getParameterIndex(psiParameter); return psiParameter; } }); }