Configure Kotlin: restore all changed files in undo action
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
## 1.0.2
|
## 1.0.2
|
||||||
- Show only changed files in notification "Kotlin not configured"
|
- Show only changed files in notification "Kotlin not configured"
|
||||||
|
- Configure Kotlin: restore all changed files in undo action
|
||||||
|
|
||||||
### JVM
|
### JVM
|
||||||
- Remove the compiler option "Xmultifile-facades-open"
|
- Remove the compiler option "Xmultifile-facades-open"
|
||||||
|
|||||||
+38
-34
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.idea.configuration;
|
|||||||
import com.intellij.codeInsight.CodeInsightUtilCore;
|
import com.intellij.codeInsight.CodeInsightUtilCore;
|
||||||
import com.intellij.ide.actions.OpenFileAction;
|
import com.intellij.ide.actions.OpenFileAction;
|
||||||
import com.intellij.openapi.application.Result;
|
import com.intellij.openapi.application.Result;
|
||||||
|
import com.intellij.openapi.command.CommandProcessor;
|
||||||
import com.intellij.openapi.command.WriteCommandAction;
|
import com.intellij.openapi.command.WriteCommandAction;
|
||||||
import com.intellij.openapi.module.Module;
|
import com.intellij.openapi.module.Module;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.DependencyScope;
|
import com.intellij.openapi.roots.DependencyScope;
|
||||||
import com.intellij.openapi.roots.ExternalLibraryDescriptor;
|
import com.intellij.openapi.roots.ExternalLibraryDescriptor;
|
||||||
import com.intellij.openapi.roots.FileIndexFacade;
|
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import com.intellij.openapi.vfs.VfsUtil;
|
import com.intellij.openapi.vfs.VfsUtil;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
@@ -84,40 +84,45 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(@NotNull Project project, Collection<Module> excludeModules) {
|
public void configure(@NotNull final Project project, Collection<Module> excludeModules) {
|
||||||
ConfigureDialogWithModulesAndVersion dialog =
|
final ConfigureDialogWithModulesAndVersion dialog =
|
||||||
new ConfigureDialogWithModulesAndVersion(project, this, excludeModules);
|
new ConfigureDialogWithModulesAndVersion(project, this, excludeModules);
|
||||||
|
|
||||||
dialog.show();
|
dialog.show();
|
||||||
if (!dialog.isOK()) return;
|
if (!dialog.isOK()) return;
|
||||||
|
|
||||||
NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(project);
|
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||||
Set<GroovyFile> changedFiles = new HashSet<GroovyFile>();
|
@Override
|
||||||
GroovyFile projectGradleFile = getBuildGradleFile(project, getTopLevelProjectFilePath(project));
|
public void run() {
|
||||||
if (projectGradleFile != null && canConfigureFile(projectGradleFile)) {
|
NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(project);
|
||||||
boolean isModified = changeGradleFile(projectGradleFile, true, dialog.getKotlinVersion(), collector);
|
Set<GroovyFile> changedFiles = new HashSet<GroovyFile>();
|
||||||
if (isModified) {
|
GroovyFile projectGradleFile = getBuildGradleFile(project, getTopLevelProjectFilePath(project));
|
||||||
changedFiles.add(projectGradleFile);
|
if (projectGradleFile != null && canConfigureFile(projectGradleFile)) {
|
||||||
}
|
boolean isModified = changeGradleFile(projectGradleFile, true, dialog.getKotlinVersion(), collector);
|
||||||
}
|
if (isModified) {
|
||||||
|
changedFiles.add(projectGradleFile);
|
||||||
for (Module module : dialog.getModulesToConfigure()) {
|
}
|
||||||
GroovyFile file = getBuildGradleFile(project, getModuleFilePath(module));
|
|
||||||
if (file != null && canConfigureFile(file)) {
|
|
||||||
boolean isModified = changeGradleFile(file, false, dialog.getKotlinVersion(), collector);
|
|
||||||
if (isModified) {
|
|
||||||
changedFiles.add(file);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
showErrorMessage(project, "Cannot find build.gradle file for module " + module.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (GroovyFile file : changedFiles) {
|
for (Module module : dialog.getModulesToConfigure()) {
|
||||||
OpenFileAction.openFile(file.getVirtualFile(), project);
|
GroovyFile file = getBuildGradleFile(project, getModuleFilePath(module));
|
||||||
}
|
if (file != null && canConfigureFile(file)) {
|
||||||
collector.showNotification();
|
boolean isModified = changeGradleFile(file, false, dialog.getKotlinVersion(), collector);
|
||||||
|
if (isModified) {
|
||||||
|
changedFiles.add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
showErrorMessage(project, "Cannot find build.gradle file for module " + module.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (GroovyFile file : changedFiles) {
|
||||||
|
OpenFileAction.openFile(file.getVirtualFile(), project);
|
||||||
|
}
|
||||||
|
collector.showNotification();
|
||||||
|
}
|
||||||
|
}, "Configure Kotlin", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addKotlinLibraryToModule(final Module module, final DependencyScope scope, final ExternalLibraryDescriptor libraryDescriptor) {
|
public static void addKotlinLibraryToModule(final Module module, final DependencyScope scope, final ExternalLibraryDescriptor libraryDescriptor) {
|
||||||
@@ -257,8 +262,7 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrClosableBlock dependenciesBlock = getDependenciesBlock(file);
|
GrClosableBlock dependenciesBlock = getDependenciesBlock(file);
|
||||||
Module module = FileIndexFacade.getInstance(file.getProject()).getModuleForFile(file.getVirtualFile());
|
wasModified |= addExpressionInBlockIfNeeded(LIBRARY, dependenciesBlock, false);
|
||||||
wasModified |= addExpressionInBlockIfNeeded(LIBRARY, dependenciesBlock, false, !ConfigureKotlinInProjectUtilsKt.hasKotlinRuntimeInScope(module));
|
|
||||||
|
|
||||||
wasModified |= addSourceSetsBlock(file);
|
wasModified |= addSourceSetsBlock(file);
|
||||||
|
|
||||||
@@ -383,11 +387,11 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean addLastExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
protected static boolean addLastExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
||||||
return addExpressionInBlockIfNeeded(text, block, false, false);
|
return addExpressionInBlockIfNeeded(text, block, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean addFirstExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
private static boolean addFirstExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
||||||
return addExpressionInBlockIfNeeded(text, block, true, false);
|
return addExpressionInBlockIfNeeded(text, block, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -405,8 +409,8 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean addExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block, boolean isFirst, boolean forceInsert) {
|
private static boolean addExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block, boolean isFirst) {
|
||||||
if (!forceInsert && block.getText().contains(text)) return false;
|
if (block.getText().contains(text)) return false;
|
||||||
GrExpression newStatement = GroovyPsiElementFactory.getInstance(block.getProject()).createExpressionFromText(text);
|
GrExpression newStatement = GroovyPsiElementFactory.getInstance(block.getProject()).createExpressionFromText(text);
|
||||||
CodeStyleManager.getInstance(block.getProject()).reformat(newStatement);
|
CodeStyleManager.getInstance(block.getProject()).reformat(newStatement);
|
||||||
GrStatement[] statements = block.getStatements();
|
GrStatement[] statements = block.getStatements();
|
||||||
|
|||||||
Reference in New Issue
Block a user