use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class FindUsagesTest method testNonCodeClassUsages.
public void testNonCodeClassUsages() throws Exception {
final TempDirTestFixture tdf = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
tdf.setUp();
try {
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(getProject()).getModifiableModel();
moduleModel.newModule("independent/independent.iml", StdModuleTypes.JAVA.getId());
moduleModel.commit();
tdf.createFile("plugin.xml", "<document>\n" + " <action class=\"com.Foo\" />\n" + " <action class=\"com.Foo.Bar\" />\n" + " <action class=\"com.Foo$Bar\" />\n" + "</document>");
PsiTestUtil.addContentRoot(ModuleManager.getInstance(getProject()).findModuleByName("independent"), tdf.getFile(""));
}
}.execute();
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
PsiClass foo = myJavaFacade.findClass("com.Foo", scope);
PsiClass bar = myJavaFacade.findClass("com.Foo.Bar", scope);
final int[] count = { 0 };
Processor<UsageInfo> processor = usageInfo -> {
int navigationOffset = usageInfo.getNavigationOffset();
assertTrue(navigationOffset > 0);
String textAfter = usageInfo.getFile().getText().substring(navigationOffset);
assertTrue(textAfter, textAfter.startsWith("Foo") || textAfter.startsWith("Bar") || textAfter.startsWith("com.Foo.Bar"));
count[0]++;
return true;
};
JavaFindUsagesHandler handler = new JavaFindUsagesHandler(bar, JavaFindUsagesHandlerFactory.getInstance(getProject()));
count[0] = 0;
handler.processUsagesInText(foo, processor, scope);
assertEquals(3, count[0]);
count[0] = 0;
handler.processUsagesInText(bar, processor, scope);
assertEquals(2, count[0]);
} finally {
tdf.tearDown();
}
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class FindClassTest method configureTwoMoreModules.
private List<Module> configureTwoMoreModules() {
final List<Module> newModules = ContainerUtil.newArrayList();
ApplicationManager.getApplication().runWriteAction(() -> {
ModifiableModuleModel modifiableModel = ModuleManager.getInstance(getProject()).getModifiableModel();
Module module2 = modifiableModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
newModules.add(module2);
ModuleRootModificationUtil.addDependency(module2, getModule());
File repoLib = new File(PathManagerEx.getTestDataPath(), "/psi/cls/repo/");
VirtualFile repoRoot = LocalFileSystem.getInstance().findFileByIoFile(repoLib);
assertNotNull(repoRoot);
ModuleRootModificationUtil.addModuleLibrary(module2, repoRoot.getUrl());
newModules.add(modifiableModel.newModule("b.iml", StdModuleTypes.JAVA.getId()));
modifiableModel.commit();
});
return newModules;
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class ModuleRootManagerImpl method commitModel.
void commitModel(RootModelImpl rootModel) {
ApplicationManager.getApplication().assertWriteAccessAllowed();
LOG.assertTrue(rootModel.myModuleRootManager == this);
boolean changed = rootModel.isChanged();
final Project project = myModule.getProject();
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel();
ModifiableModelCommitter.multiCommit(Collections.singletonList(rootModel), moduleModel);
if (changed) {
stateChanged();
}
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class PsiTestUtil method addModule.
public static Module addModule(Project project, ModuleType type, String name, VirtualFile root) {
return new WriteCommandAction<Module>(project) {
@Override
protected void run(@NotNull Result<Module> result) throws Throwable {
String moduleName;
ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel();
try {
moduleName = moduleModel.newModule(root.getPath() + "/" + name + ".iml", type.getId()).getName();
moduleModel.commit();
} catch (Throwable t) {
moduleModel.dispose();
throw t;
}
Module dep = ModuleManager.getInstance(project).findModuleByName(moduleName);
assert dep != null : moduleName;
ModifiableRootModel model = ModuleRootManager.getInstance(dep).getModifiableModel();
try {
model.addContentEntry(root).addSourceFolder(root, false);
model.commit();
} catch (Throwable t) {
model.dispose();
throw t;
}
result.setResult(dep);
}
}.execute().getResultObject();
}
use of com.intellij.openapi.module.ModifiableModuleModel in project android by JetBrains.
the class ProjectResourceRepositoryTest method renameModule.
private static void renameModule(Module from, String name) throws ModuleWithNameAlreadyExists {
final ModifiableModuleModel model = ModuleManager.getInstance(from.getProject()).getModifiableModel();
model.renameModule(from, name);
ApplicationManager.getApplication().runWriteAction(model::commit);
}
Aggregations