本文整理汇总了Java中com.intellij.openapi.command.WriteCommandAction类的典型用法代码示例。如果您正苦于以下问题:Java WriteCommandAction类的具体用法?Java WriteCommandAction怎么用?Java WriteCommandAction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WriteCommandAction类属于com.intellij.openapi.command包,在下文中一共展示了WriteCommandAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
public void build(PsiFile psiFile, Project project1, Editor editor) {
if (psiFile == null) return;
WriteCommandAction.runWriteCommandAction(project1, () -> {
if (editor == null) return;
Project project = editor.getProject();
if (project == null) return;
PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (psiClass == null) return;
if (psiClass.getNameIdentifier() == null) return;
String className = psiClass.getNameIdentifier().getText();
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
build(editor, elementFactory, project, psiClass, className);
JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
styleManager.optimizeImports(psiFile);
styleManager.shortenClassReferences(psiClass);
});
}
示例2: actionPerformed
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
RefmtManager refmt = RefmtManager.getInstance();
if (refmt != null) {
PsiFile file = e.getData(PSI_FILE);
Project project = e.getProject();
if (project != null && file != null && (file instanceof OclFile || file instanceof RmlFile)) {
String format = file instanceof OclFile ? "ml" : "re";
Document document = PsiDocumentManager.getInstance(project).getDocument(file);
if (document != null) {
//WriteCommandAction.writeCommandAction(project).run(() -> refmt.refmt(project, format, document));
WriteCommandAction.runWriteCommandAction(project, () -> refmt.refmt(project, format, document)); // idea#143
}
}
}
}
示例3: actionPerformed
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
/**
* Inserts the string generated by {@link #generateString()} at the caret(s) in the editor.
*
* @param event the performed action
*/
@Override
public final void actionPerformed(final AnActionEvent event) {
final Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor == null) {
return;
}
final Project project = event.getData(CommonDataKeys.PROJECT);
final Document document = editor.getDocument();
final CaretModel caretModel = editor.getCaretModel();
final Runnable replaceCaretSelections = () -> caretModel.getAllCarets().forEach(caret -> {
final int start = caret.getSelectionStart();
final int end = caret.getSelectionEnd();
final String string = generateString();
final int newEnd = start + string.length();
document.replaceString(start, end, string);
caret.setSelection(start, newEnd);
});
WriteCommandAction.runWriteCommandAction(project, replaceCaretSelections);
}
示例4: upgrade
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
@Override
public void upgrade(@NotNull DependencyInfo dependencyInfo, @NotNull Listener listener)
{
if (upgrading)
{
return;
}
upgrading = true;
WriteCommandAction.runWriteCommandAction(project, () ->
{
MavenHelper.upgradeDependency(project.getBaseDir(), dependencyInfo);
GradleHelper.upgradeDependency(project.getBaseDir(), dependencyInfo);
listener.upgradeDone(dependencyInfo);
upgrading = false;
});
}
示例5: configureProject
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
@Override
public void configureProject(@NotNull final Project project, @NotNull final VirtualFile baseDir,
@NotNull PyNewProjectSettings settings,
@NotNull Module module,
@Nullable final PyProjectSynchronizer synchronizer) {
final Course course = getCourse(project, mySettingsPanel);
EduUsagesCollector.projectTypeCreated(CCUtils.COURSE_MODE);
final CCProjectComponent component = project.getComponent(CCProjectComponent.class);
component.registerListener();
final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(baseDir);
if (projectDir == null) return;
new WriteCommandAction.Simple(project) {
@Override
protected void run() throws Throwable {
createTestHelper(project, projectDir);
PsiDirectory lessonDir = new CCCreateLesson().createItem(null, project, projectDir, course);
if (lessonDir == null) {
LOG.error("Failed to create lesson");
return;
}
new CCCreateTask().createItem(null, project, lessonDir, course);
}
}.execute();
}
示例6: actionPerformed
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
dialog.show();
int exitCode = dialog.getExitCode();
if (exitCode != CANCEL_EXIT_CODE) {
String key = dialog.getKeyText();
String value = dialog.getValueText();
currentLang = dialog.getSelectedLangauge();
if (currentLang != null && !currentLang.isEmpty()) {
Editor ieditor = editorMap.get(currentLang);
Document document = ieditor.getDocument();
WriteCommandAction.runWriteCommandAction(fileEditor.getProject(), () -> updateDocumentHook(document, ieditor.getProject(), currentLang, key, value, model));
} else {
NotificationHelper.showBaloon("No language file available", MessageType.WARNING, fileEditor.getProject());
}
}
}
示例7: executeTestConfiguration
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
private void executeTestConfiguration(int binarySettings, String relativeTargetPath, boolean checkResults) {
if (relativeTargetPath == null || relativeTargetPath.isEmpty()) {
relativeTargetPath = ".";
}
myFixture.configureByFiles(relativeTargetPath + "/TestData.csv");
initCsvCodeStyleSettings(binarySettings);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(),
ContainerUtil.newArrayList(myFixture.getFile().getTextRange()));
}
}.execute();
if (checkResults) {
myFixture.checkResultByFile(relativeTargetPath + String.format("/TestResult%08d.csv", binarySettings));
}
}
示例8: _testResultGenerator
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
/**
* This function should be executed (remove the underscore) if the current results are correct (manual testing).
*
* @throws Exception
*/
public void _testResultGenerator() throws Exception {
for (int binarySettings = 0; binarySettings < 128; ++binarySettings) {
tearDown();
setUp();
myFixture.configureByFiles("/generated/TestData.csv");
initCsvCodeStyleSettings(binarySettings);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(),
ContainerUtil.newArrayList(myFixture.getFile().getTextRange()));
}
}.execute();
try (PrintWriter writer = new PrintWriter(getTestDataPath() + String.format("/generated/TestResult%08d.csv", binarySettings))
) {
writer.print(myFixture.getFile().getText());
}
}
}
示例9: testSaveAllDocuments_DocumentWasChanged
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
public void testSaveAllDocuments_DocumentWasChanged() throws Exception {
final VirtualFile file = createFile();
final long stamp = file.getModificationStamp();
final Document document = myDocumentManager.getDocument(file);
assertNotNull(file.toString(), document);
WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
@Override
public void run() {
document.insertString(0, "xxx ");
}
});
myDocumentManager.saveAllDocuments();
assertNotEquals(stamp, file.getModificationStamp());
assertEquals("xxx test", new String(file.contentsToByteArray(), CharsetToolkit.UTF8_CHARSET));
}
示例10: testMoveIntoResourceFolder
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
public void testMoveIntoResourceFolder() throws Exception {
// Move value files out of its resource folder; items should disappear
final VirtualFile file1 = myFixture.copyFileToProject(VALUES1, "res/values/dummy.ignore");
final VirtualFile xmlFile = myFixture.copyFileToProject(VALUES1, "src/my/pkg/values.xml");
PsiFile psiFile1 = PsiManager.getInstance(getProject()).findFile(file1);
assertNotNull(psiFile1);
final ResourceFolderRepository resources = createRepository();
assertNotNull(resources);
assertFalse(resources.hasResourceItem(ResourceType.STRING, "title_template_step"));
final long generation = resources.getModificationCount();
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
try {
xmlFile.move(this, file1.getParent());
}
catch (IOException e) {
fail(e.toString());
}
}
});
assertTrue(generation < resources.getModificationCount());
assertTrue(resources.hasResourceItem(ResourceType.STRING, "title_template_step"));
}
示例11: testSetAttributeWithQuotes2
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
public void testSetAttributeWithQuotes2() throws Exception {
final XmlTag rootTag = XmlElementFactory.getInstance(getProject()).createTagFromText("<html/>");
final String value = "'a \"b\" c'";
WriteCommandAction.runWriteCommandAction(null, new Runnable(){
@Override
public void run() {
rootTag.setAttribute("foo", value);
}
});
final String expected = value.replaceAll("\"", """);
assertEquals(1, rootTag.getAttributes().length);
assertEquals(expected, rootTag.getAttributeValue("foo"));
assertEquals(value, rootTag.getAttribute("foo").getDisplayValue());
assertEquals("foo", rootTag.getAttributes()[0].getName());
assertEquals("<html foo=\"" + expected + "\"/>", rootTag.getText());
}
示例12: actionPerformed
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) {
final SimpleNode selectedNode = treeView.getTree().getSelectedNode();
if (selectedNode instanceof BaseDomElementNode) {
if (selectedNode instanceof DomFileElementNode) {
e.getPresentation().setVisible(false);
return;
}
final DomElement domElement = ((BaseDomElementNode)selectedNode).getDomElement();
final int ret = Messages.showOkCancelDialog(getPresentationText(selectedNode, "Remove") + "?", "Remove",
Messages.getQuestionIcon());
if (ret == Messages.OK) {
new WriteCommandAction(domElement.getManager().getProject(), DomUtil.getFile(domElement)) {
@Override
protected void run(@NotNull final Result result) throws Throwable {
domElement.undefine();
}
}.execute();
}
}
}
示例13: createLog4JTest
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
private VirtualFile createLog4JTest(final Project project, final MavenId projectId, final VirtualFile appDirectory)
{
return new WriteCommandAction<VirtualFile>(project, "Create Log4J Test File", PsiFile.EMPTY_ARRAY)
{
@Override
protected void run(@NotNull Result<VirtualFile> result) throws Throwable
{
try
{
VirtualFile configFile = appDirectory.findOrCreateChildData(this, "log4j2-test.xml");
final FileTemplateManager manager = FileTemplateManager.getInstance(project);
final FileTemplate template = manager.getInternalTemplate(MuleFileTemplateDescriptorManager.LOG4J2_TEST);
final Properties defaultProperties = manager.getDefaultProperties();
final String text = template.getText(defaultProperties);
VfsUtil.saveText(configFile, text);
result.setResult(configFile);
}
catch (IOException e)
{
showError(project, e);
}
}
}.execute().getResultObject();
}
示例14: _testReparsePerformance
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
public void _testReparsePerformance() throws Exception {
final String text = loadFile("performance2.xml");
final PsiFile file = createFile("test.xml", text);
transformAllChildren(file.getNode());
final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file);
System.gc();
System.gc();
new WriteCommandAction(getProject(), file) {
@Override
protected void run(@NotNull final Result result) throws Throwable {
PlatformTestUtil.startPerformanceTest("XML reparse using PsiBuilder", 2500, new ThrowableRunnable() {
@Override
public void run() throws Exception {
for (int i = 0; i < 10; i++) {
final long tm = System.currentTimeMillis();
doc.insertString(0, "<additional root=\"tag\"/>");
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
System.out.println("Reparsed for: " + (System.currentTimeMillis() - tm));
}
}
}).cpuBound().assertTiming();
}
}.execute();
}
示例15: invoke
import com.intellij.openapi.command.WriteCommandAction; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, @NotNull final Editor editor, @NotNull PsiFile file) throws IncorrectOperationException {
final PsiElement element = currentCommaElement(editor, file);
if (element != null) {
new WriteCommandAction(project, file) {
protected void run(@NotNull Result result) throws Throwable {
PostprocessReformattingAspect.getInstance(getProject()).disablePostprocessFormattingInside(new Runnable() {
@Override
public void run() {
swapAtComma(editor, element);
}
});
}
}.execute();
}
}