mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PsiTestUtil#addModule,addDependency
This commit is contained in:
@@ -20,7 +20,10 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.module.ModifiableModuleModel;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.*;
|
||||
@@ -297,4 +300,35 @@ import java.util.Collection;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Module addModule(final Project project, final ModuleType type, final String name, final VirtualFile root) {
|
||||
return new WriteCommandAction<Module>(project) {
|
||||
@Override
|
||||
protected void run(Result<Module> result) throws Throwable {
|
||||
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel();
|
||||
String moduleName = moduleModel.newModule(root.getPath() + "/" + name + ".iml", type).getName();
|
||||
moduleModel.commit();
|
||||
|
||||
final Module dep = ModuleManager.getInstance(project).findModuleByName(moduleName);
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(dep).getModifiableModel();
|
||||
final ContentEntry entry = model.addContentEntry(root);
|
||||
entry.addSourceFolder(root, false);
|
||||
|
||||
model.commit();
|
||||
result.setResult(dep);
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
}
|
||||
|
||||
public static void addDependency(final Module from, final Module to) {
|
||||
new WriteCommandAction(from.getProject()) {
|
||||
@Override
|
||||
protected void run(Result result) throws Throwable {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(from).getModifiableModel();
|
||||
model.addModuleOrderEntry(to);
|
||||
model.commit();
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiFile
|
||||
import junit.framework.AssertionFailedError
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -301,8 +302,8 @@ public class Transf implements ASTTransformation {
|
||||
|
||||
Module dep1 = addModule('dependent1')
|
||||
Module dep2 = addModule('dependent2')
|
||||
addDependency dep2, dep1
|
||||
addDependency myModule, dep2
|
||||
PsiTestUtil.addDependency dep2, dep1
|
||||
PsiTestUtil.addDependency myModule, dep2
|
||||
|
||||
addGroovyLibrary(dep1);
|
||||
addGroovyLibrary(dep2);
|
||||
|
||||
+1
-13
@@ -150,22 +150,10 @@ public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestC
|
||||
|
||||
protected Module addDependentModule() {
|
||||
Module module = addModule("dependent");
|
||||
addDependency(module, myModule);
|
||||
PsiTestUtil.addDependency(module, myModule);
|
||||
return module;
|
||||
}
|
||||
|
||||
protected void addDependency(final Module from, final Module to) {
|
||||
new WriteCommandAction(getProject()) {
|
||||
@Override
|
||||
protected void run(Result result) throws Throwable {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(from).getModifiableModel();
|
||||
model.addModuleOrderEntry(to);
|
||||
model.commit();
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
|
||||
}
|
||||
|
||||
protected Module addModule(final String name) {
|
||||
return new WriteCommandAction<Module>(getProject()) {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user