Search in sources :

Example 16 with ModifiableModuleModel

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();
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture) ModuleManager(com.intellij.openapi.module.ModuleManager) JavaFindUsagesHandlerFactory(com.intellij.find.findUsages.JavaFindUsagesHandlerFactory) UsageInfo(com.intellij.usageView.UsageInfo) IntArrayList(com.intellij.util.containers.IntArrayList) ArrayList(java.util.ArrayList) MethodReferencesSearch(com.intellij.psi.search.searches.MethodReferencesSearch) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) IdeaTestUtil(com.intellij.testFramework.IdeaTestUtil) PsiTestCase(com.intellij.testFramework.PsiTestCase) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) PsiTestUtil(com.intellij.testFramework.PsiTestUtil) JavaTestUtil(com.intellij.JavaTestUtil) OverridingMethodsSearch(com.intellij.psi.search.searches.OverridingMethodsSearch) Collection(java.util.Collection) TextRange(com.intellij.openapi.util.TextRange) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) JavaFindUsagesHandler(com.intellij.find.findUsages.JavaFindUsagesHandler) List(java.util.List) Result(com.intellij.openapi.application.Result) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) IdeaTestFixtureFactory(com.intellij.testFramework.fixtures.IdeaTestFixtureFactory) Collections(java.util.Collections) TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture) JavaFindUsagesHandler(com.intellij.find.findUsages.JavaFindUsagesHandler) Result(com.intellij.openapi.application.Result) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) UsageInfo(com.intellij.usageView.UsageInfo)

Example 17 with ModifiableModuleModel

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 18 with ModifiableModuleModel

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();
    }
}
Also used : Project(com.intellij.openapi.project.Project) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel)

Example 19 with ModifiableModuleModel

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();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with ModifiableModuleModel

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);
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel)

Aggregations

ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)44 Module (com.intellij.openapi.module.Module)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 ModuleManager (com.intellij.openapi.module.ModuleManager)10 Project (com.intellij.openapi.project.Project)9 NotNull (org.jetbrains.annotations.NotNull)8 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5 File (java.io.File)5 Result (com.intellij.openapi.application.Result)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (aQute.bnd.build.Project)2 MoveModulesToSubGroupAction (com.intellij.ide.projectView.actions.MoveModulesToSubGroupAction)2 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)2