com.intellij.openapi.vfs.VirtualFile

Here are the examples of the java api class com.intellij.openapi.vfs.VirtualFile taken from open source projects.

1. SearchInLibsTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    String root = JavaTestUtil.getJavaTestDataPath() + "/psi/search/searchInLibs";
    VirtualFile rootFile = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete, false);
    final VirtualFile projectRoot = rootFile.findChild("project");
    assertNotNull(projectRoot);
    final VirtualFile innerSourceRoot = projectRoot.findChild("src2");
    assertNotNull(innerSourceRoot);
    VirtualFile libRoot = rootFile.findChild("lib");
    final VirtualFile libClassesRoot = libRoot.findChild("classes");
    final VirtualFile libSrcRoot = libRoot.findChild("src");
    final VirtualFile libSrc2Root = libRoot.findChild("src2");
    assertNotNull(libRoot);
    PsiTestUtil.removeAllRoots(myModule, null);
    PsiTestUtil.addSourceRoot(myModule, projectRoot);
    PsiTestUtil.addSourceRoot(myModule, innerSourceRoot);
    List<String> sourceRoots = Arrays.asList(libSrcRoot.getUrl(), libSrc2Root.getUrl());
    List<String> classesRoots = Collections.singletonList(libClassesRoot.getUrl());
    ModuleRootModificationUtil.addModuleLibrary(myModule, "lib", classesRoots, sourceRoots);
}

2. PatchCreatorTest#testDirectoryDeletionWithFiles()

Project: consulo
Source File: PatchCreatorTest.java
View license
public void testDirectoryDeletionWithFiles() throws Exception {
    VirtualFile dir = myRoot.createChildDirectory(null, "dir");
    dir.createChildData(null, "f1.txt");
    dir.createChildData(null, "f2.txt");
    dir.delete(null);
    createPatchBetweenRevisions(1, 0, false);
    dir = myRoot.createChildDirectory(null, "dir");
    dir.createChildData(null, "f1.txt");
    dir.createChildData(null, "f2.txt");
    applyPatch();
    assertNotNull(myRoot.findChild("dir"));
    assertNull(myRoot.findChild("dir").findChild("f1.txt"));
    assertNull(myRoot.findChild("dir").findChild("f2.txt"));
}

3. PatchCreatorTest#testDirectoryRename()

Project: consulo
Source File: PatchCreatorTest.java
View license
public void testDirectoryRename() throws Exception {
    VirtualFile dir = myRoot.createChildDirectory(null, "dir1");
    dir.createChildData(null, "f.txt");
    dir.rename(null, "dir2");
    createPatchBetweenRevisions(1, 0);
    dir.rename(null, "dir1");
    applyPatch();
    VirtualFile afterDir1 = myRoot.findChild("dir1");
    VirtualFile afterDir2 = myRoot.findChild("dir2");
    assertNotNull(afterDir1);
    assertNotNull(afterDir2);
    assertNull(afterDir1.findChild("f.txt"));
    assertNotNull(afterDir2.findChild("f.txt"));
}

4. DifferenceReverterTest#testRevertingMoveFromOldRevisionsWhenDirDoesNotExists()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testRevertingMoveFromOldRevisionsWhenDirDoesNotExists() throws Exception {
    VirtualFile dir1 = myRoot.createChildDirectory(this, "dir1");
    VirtualFile dir2 = myRoot.createChildDirectory(this, "dir2");
    VirtualFile f = dir1.createChildData(this, "foo.txt");
    f.move(this, dir2);
    dir1.delete(this);
    dir2.delete(this);
    revertChange(2);
    dir1 = myRoot.findChild("dir1");
    assertNotNull(dir1);
    assertNull(myRoot.findChild("dir2"));
    assertNotNull(dir1.findChild("foo.txt"));
}

5. PatchCreatorTest#testRename()

Project: consulo
Source File: PatchCreatorTest.java
View license
public void testRename() throws Exception {
    VirtualFile f = myRoot.createChildData(null, "f.txt");
    f.setBinaryContent(new byte[] { 1 });
    f.rename(null, "ff.txt");
    createPatchBetweenRevisions(1, 0);
    f.rename(null, "f.txt");
    applyPatch();
    VirtualFile patched = myRoot.findChild("ff.txt");
    assertNull(myRoot.findChild("f.txt"));
    assertNotNull(patched);
    assertEquals(1, patched.contentsToByteArray()[0]);
}

6. DifferenceReverterTest#testDirDeletion()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testDirDeletion() throws Exception {
    VirtualFile dir = myRoot.createChildDirectory(this, "dir");
    VirtualFile subdir = dir.createChildDirectory(this, "subdir");
    VirtualFile f = subdir.createChildData(this, "foo.txt");
    f.setBinaryContent(new byte[] { 123 }, -1, 4000);
    dir.delete(this);
    revertLastChange();
    dir = myRoot.findChild("dir");
    subdir = dir.findChild("subdir");
    f = subdir.findChild("foo.txt");
    assertNotNull(f);
    assertEquals(123, f.contentsToByteArray()[0]);
    assertEquals(4000, f.getTimeStamp());
}

7. DifferenceReverterTest#testMovement()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testMovement() throws Exception {
    VirtualFile dir1 = myRoot.createChildDirectory(this, "dir1");
    VirtualFile dir2 = myRoot.createChildDirectory(this, "dir2");
    VirtualFile f = dir1.createChildData(this, "foo.txt");
    f.setBinaryContent(new byte[] { 123 }, -1, 4000);
    f.move(this, dir2);
    revertLastChange();
    assertNull(dir2.findChild("foo.txt"));
    f = dir1.findChild("foo.txt");
    assertNotNull(f);
    assertEquals(123, f.contentsToByteArray()[0]);
    assertEquals(4000, f.getTimeStamp());
}

8. DifferenceReverterTest#testParentAndChildRename()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testParentAndChildRename() throws Exception {
    VirtualFile dir = myRoot.createChildDirectory(this, "dir");
    VirtualFile f = dir.createChildData(this, "foo.txt");
    f.setBinaryContent(new byte[] { 123 }, -1, 4000);
    getVcs().beginChangeSet();
    dir.rename(this, "dir2");
    f.rename(this, "bar.txt");
    getVcs().endChangeSet(null);
    revertLastChange();
    assertNull(myRoot.findChild("dir2"));
    dir = myRoot.findChild("dir");
    assertNull(dir.findChild("bar.txt"));
    f = dir.findChild("foo.txt");
    assertNotNull(f);
    assertEquals(123, f.contentsToByteArray()[0]);
    assertEquals(4000, f.getTimeStamp());
}

9. DifferenceReverterTest#testRevertingContentChangeFromOldRevisionsWhenDirDoesNotExists()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testRevertingContentChangeFromOldRevisionsWhenDirDoesNotExists() throws Exception {
    VirtualFile dir = myRoot.createChildDirectory(this, "dir");
    VirtualFile f = dir.createChildData(this, "foo.txt");
    f.setBinaryContent(new byte[] { 1 }, -1, 1000);
    f.setBinaryContent(new byte[] { 2 }, -1, 2000);
    dir.delete(this);
    revertChange(1);
    dir = myRoot.findChild("dir");
    assertNotNull(dir);
    f = dir.findChild("foo.txt");
    assertNotNull(f);
    assertEquals(1, f.contentsToByteArray()[0]);
    assertEquals(1000, f.getTimeStamp());
}

10. FileHistoryDialogTest#testTitles()

Project: consulo
Source File: FileHistoryDialogTest.java
View license
public void testTitles() throws IOException {
    long leftTime = new Date(2001 - 1900, 1, 3, 12, 0).getTime();
    long rightTime = new Date(2002 - 1900, 2, 4, 14, 0).getTime();
    VirtualFile f = myRoot.createChildData(null, "old.txt");
    f.setBinaryContent("old".getBytes(), -1, leftTime);
    f.rename(null, "new.txt");
    f.setBinaryContent("new".getBytes(), -1, rightTime);
    // to create current content to skip.
    f.setBinaryContent(new byte[0]);
    FileHistoryDialogModel m = createFileModelAndSelectRevisions(f, 0, 2);
    assertEquals(FileUtil.toSystemDependentName(f.getPath()), m.getDifferenceModel().getTitle());
    assertEquals(DateFormatUtil.formatPrettyDateTime(leftTime) + " - old.txt", m.getDifferenceModel().getLeftTitle(new NullRevisionsProgress()));
    assertEquals(DateFormatUtil.formatPrettyDateTime(rightTime) + " - new.txt", m.getDifferenceModel().getRightTitle(new NullRevisionsProgress()));
}

11. CopyTest#testPackageInfo()

Project: intellij-community
Source File: CopyTest.java
View license
public void testPackageInfo() throws Exception {
    String rootBefore = getRoot();
    PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
    final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
    final VirtualFile first = root.findFileByRelativePath("from/package-info.java");
    assertNotNull(first);
    final PsiFile firstPsi = myPsiManager.findFile(first);
    assertTrue(CopyHandler.canCopy(new PsiElement[] { firstPsi }));
    final VirtualFile toDir = root.findChild("to");
    assertNotNull(toDir);
    final PsiDirectory targetDirectory = myPsiManager.findDirectory(toDir);
    CopyHandler.doCopy(new PsiElement[] { firstPsi }, targetDirectory);
    final VirtualFile dest = root.findFileByRelativePath("to/package-info.java");
    assertNotNull(dest);
    VirtualFile fileExpected = root.findFileByRelativePath("to/package-info.expected.java");
    PlatformTestUtil.assertFilesEqual(fileExpected, dest);
}

12. ModuleScopesTest#testRuntimeLibraryDependency()

View license
public void testRuntimeLibraryDependency() throws IOException {
    Module m = createModule("a.iml", StdModuleTypes.JAVA);
    VirtualFile libraryRoot = addLibrary(m, DependencyScope.RUNTIME);
    final VirtualFile[] runtimeClasspath = getRuntimeClasspath(m);
    assertOrderedEquals(runtimeClasspath, libraryRoot);
    final VirtualFile[] compilationClasspath = getCompilationClasspath(m);
    assertEquals(1, compilationClasspath.length);
    VirtualFile[] production = getProductionCompileClasspath(m);
    assertEmpty(production);
    VirtualFile libraryClass = myFixture.createFile("lib/Test.class");
    assertFalse(m.getModuleWithDependenciesAndLibrariesScope(true).contains(libraryClass));
    assertFalse(m.getModuleWithDependenciesAndLibrariesScope(false).contains(libraryClass));
    assertTrue(m.getModuleRuntimeScope(true).contains(libraryClass));
    assertTrue(m.getModuleRuntimeScope(false).contains(libraryClass));
}

13. ArtifactCompilerTestCase#changeFileInJar()

View license
protected void changeFileInJar(String jarPath, String pathInJar) throws Exception {
    final VirtualFile jarFile = LocalFileSystem.getInstance().findFileByPath(jarPath);
    assertNotNull(jarFile);
    final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(jarFile);
    assertNotNull(jarRoot);
    VirtualFile jarEntry = jarRoot.findFileByRelativePath(pathInJar);
    assertNotNull(jarEntry);
    assertNotNull(jarFile);
    changeFile(jarFile);
    jarFile.refresh(false, false);
    jarEntry = jarRoot.findFileByRelativePath(pathInJar);
    assertNotNull(jarEntry);
}

14. DifferenceReverterTest#testParentRename()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testParentRename() throws Exception {
    VirtualFile dir = myRoot.createChildDirectory(this, "dir");
    VirtualFile f = dir.createChildData(this, "foo.txt");
    f.setBinaryContent(new byte[] { 123 }, -1, 4000);
    dir.rename(this, "dir2");
    revertLastChange();
    assertNull(myRoot.findChild("dir2"));
    dir = myRoot.findChild("dir");
    f = dir.findChild("foo.txt");
    assertNotNull(f);
    assertEquals(123, f.contentsToByteArray()[0]);
    assertEquals(4000, f.getTimeStamp());
}

15. DifferenceReverterTest#testContentChangeWhenDirectoryExists()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testContentChangeWhenDirectoryExists() throws Exception {
    VirtualFile f = myRoot.createChildData(this, "foo.txt");
    f.setBinaryContent(new byte[] { 1 }, -1, 1000);
    getVcs().beginChangeSet();
    f.rename(this, "bar.txt");
    f.setBinaryContent(new byte[] { 2 }, -1, 2000);
    getVcs().endChangeSet(null);
    myRoot.createChildDirectory(this, "foo.txt");
    revertChange(1, 0, 1);
    assertNull(myRoot.findChild("bar.txt"));
    f = myRoot.findChild("foo.txt");
    assertNotNull(f);
    assertFalse(f.isDirectory());
    assertEquals(1, f.contentsToByteArray()[0]);
    assertEquals(1000, f.getTimeStamp());
}

16. DifferenceReverterTest#testRevertingRenameFromOldRevisionsWhenDirDoesNotExists()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testRevertingRenameFromOldRevisionsWhenDirDoesNotExists() throws Exception {
    VirtualFile dir = myRoot.createChildDirectory(this, "dir");
    VirtualFile f = dir.createChildData(this, "foo.txt");
    f.rename(this, "bar.txt");
    dir.delete(this);
    revertChange(1);
    dir = myRoot.findChild("dir");
    assertNotNull(dir);
    assertNotNull(dir.findChild("foo.txt"));
    assertNull(dir.findChild("bar.txt"));
}

17. FileHistoryDialogTest#testRevertion()

Project: consulo
Source File: FileHistoryDialogTest.java
View license
public void testRevertion() throws Exception {
    VirtualFile dir = myRoot.createChildDirectory(null, "oldDir");
    VirtualFile f = dir.createChildData(null, "old.txt");
    f.rename(null, "new.txt");
    dir.rename(null, "newDir");
    FileHistoryDialogModel m = createFileModelAndSelectRevisions(f, 1, 1);
    m.createReverter().revert();
    assertEquals("old.txt", f.getName());
    assertEquals(f.getParent(), dir);
    assertEquals("newDir", dir.getName());
}

18. RootIndex#calcOrderEntries()

Project: consulo
Source File: RootIndex.java
View license
private static OrderEntry[] calcOrderEntries(@NotNull RootInfo info, @NotNull MultiMap<VirtualFile, OrderEntry> depEntries, @NotNull MultiMap<VirtualFile, OrderEntry> libClassRootEntries, @NotNull MultiMap<VirtualFile, OrderEntry> libSourceRootEntries, @NotNull List<VirtualFile> hierarchy) {
    @Nullable VirtualFile libraryClassRoot = info.findLibraryRootInfo(hierarchy, false);
    @Nullable VirtualFile librarySourceRoot = info.findLibraryRootInfo(hierarchy, true);
    Set<OrderEntry> orderEntries = ContainerUtil.newLinkedHashSet();
    orderEntries.addAll(info.getLibraryOrderEntries(hierarchy, libraryClassRoot, librarySourceRoot, libClassRootEntries, libSourceRootEntries));
    for (VirtualFile root : hierarchy) {
        orderEntries.addAll(depEntries.get(root));
    }
    VirtualFile moduleContentRoot = info.findModuleRootInfo(hierarchy);
    if (moduleContentRoot != null) {
        ContainerUtil.addIfNotNull(orderEntries, info.getModuleSourceEntry(hierarchy, moduleContentRoot, libClassRootEntries));
    }
    if (orderEntries.isEmpty()) {
        return null;
    }
    OrderEntry[] array = orderEntries.toArray(new OrderEntry[orderEntries.size()]);
    Arrays.sort(array, RootIndex.BY_OWNER_MODULE);
    return array;
}

19. ArtifactCompilerTestCase#changeFileInJar()

View license
protected void changeFileInJar(String jarPath, String pathInJar) throws Exception {
    final VirtualFile jarFile = LocalFileSystem.getInstance().findFileByPath(jarPath);
    assertNotNull(jarFile);
    final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(jarFile);
    assertNotNull(jarRoot);
    VirtualFile jarEntry = jarRoot.findFileByRelativePath(pathInJar);
    assertNotNull(jarEntry);
    assertNotNull(jarFile);
    changeFile(jarFile);
    jarFile.refresh(false, false);
    jarEntry = jarRoot.findFileByRelativePath(pathInJar);
    assertNotNull(jarEntry);
}

20. AnalysisScopeTest#testGeneratedSourceRoot()

View license
public void testGeneratedSourceRoot() throws Exception {
    VirtualFile genRoot = getVirtualFile(createTempDir("genSrcRoot"));
    VirtualFile srcRoot = getVirtualFile(createTempDir("srcRoot"));
    JavaSourceRootProperties properties = JpsJavaExtensionService.getInstance().createSourceRootProperties("", true);
    PsiTestUtil.addSourceRoot(myModule, genRoot, JavaSourceRootType.SOURCE, properties);
    PsiTestUtil.addSourceRoot(myModule, srcRoot);
    VirtualFile genClass = VfsTestUtil.createFile(genRoot, "Gen.java", "class Gen{}");
    VirtualFile srcClass = VfsTestUtil.createFile(srcRoot, "Src.java", "class Src{}");
    AnalysisScope scope = new AnalysisScope(myModule);
    assertTrue(scope.contains(srcClass));
    assertFalse(scope.contains(genClass));
}

21. LibraryOrderTest#setupPaths()

View license
public void setupPaths() {
    final String basePath = JavaTestUtil.getJavaTestDataPath() + "/psi/libraryOrder/";
    final VirtualFile lib1SrcFile = refreshAndFindFile(basePath + "lib1/src");
    final VirtualFile lib1classes = refreshAndFindFile(basePath + "lib1/classes");
    final VirtualFile lib2SrcFile = refreshAndFindFile(basePath + "lib2/src");
    final VirtualFile lib2classes = refreshAndFindFile(basePath + "lib2/classes");
    assertTrue(lib1SrcFile != null);
    assertTrue(lib2SrcFile != null);
    addLibraryWithSourcePath("lib1", lib1classes, lib1SrcFile);
    addLibraryWithSourcePath("lib2", lib2classes, lib2SrcFile);
    final List<VirtualFile> list = Arrays.asList(OrderEnumerator.orderEntries(myModule).getClassesRoots());
    assertTrue(list.contains(lib1classes));
    assertTrue(list.contains(lib2classes));
}

22. CopyTest#testMultipleFiles()

Project: intellij-community
Source File: CopyTest.java
View license
public void testMultipleFiles() throws Exception {
    String rootBefore = getRoot();
    PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
    final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
    final VirtualFile first = root.findFileByRelativePath("from/1.txt");
    assertNotNull(first);
    final VirtualFile second = root.findFileByRelativePath("from/2.txt");
    assertNotNull(second);
    final PsiFile firstPsi = myPsiManager.findFile(first);
    final PsiFile secondPsi = myPsiManager.findFile(second);
    assertTrue(CopyHandler.canCopy(new PsiElement[] { firstPsi, secondPsi }));
    final VirtualFile toDir = root.findChild("to");
    assertNotNull(toDir);
    final PsiDirectory targetDirectory = myPsiManager.findDirectory(toDir);
    CopyHandler.doCopy(new PsiElement[] { firstPsi, secondPsi }, targetDirectory);
    assertNotNull(root.findFileByRelativePath("to/1.txt"));
    assertNotNull(root.findFileByRelativePath("to/2.txt"));
}

23. ModuleScopesTest#testProvidedLibraryDependency()

View license
public void testProvidedLibraryDependency() throws IOException {
    Module m = createModule("a.iml", StdModuleTypes.JAVA);
    VirtualFile libraryRoot = addLibrary(m, DependencyScope.PROVIDED);
    final VirtualFile[] runtimeClasspath = getRuntimeClasspath(m);
    assertEmpty(runtimeClasspath);
    final VirtualFile[] compilationClasspath = getCompilationClasspath(m);
    assertOrderedEquals(compilationClasspath, libraryRoot);
    VirtualFile libraryClass = myFixture.createFile("lib/Test.class");
    assertTrue(m.getModuleWithDependenciesAndLibrariesScope(true).contains(libraryClass));
    assertTrue(m.getModuleWithDependenciesAndLibrariesScope(false).contains(libraryClass));
    assertTrue(m.getModuleRuntimeScope(true).contains(libraryClass));
    assertTrue(m.getModuleRuntimeScope(false).contains(libraryClass));
}

24. OrderEnumeratorTest#testModuleSources()

View license
public void testModuleSources() throws Exception {
    final VirtualFile srcRoot = addSourceRoot(myModule, false);
    final VirtualFile testRoot = addSourceRoot(myModule, true);
    final VirtualFile output = setModuleOutput(myModule, false);
    final VirtualFile testOutput = setModuleOutput(myModule, true);
    assertClassRoots(orderEntries(myModule).withoutSdk(), testOutput, output);
    assertClassRoots(orderEntries(myModule).withoutSdk().productionOnly(), output);
    assertSourceRoots(orderEntries(myModule), srcRoot, testRoot);
    assertSourceRoots(orderEntries(myModule).productionOnly(), srcRoot);
    assertEnumeratorRoots(orderEntries(myModule).withoutSdk().classes().withoutSelfModuleOutput(), output);
    assertEnumeratorRoots(orderEntries(myModule).withoutSdk().productionOnly().classes().withoutSelfModuleOutput());
}

25. OrderEnumeratorTest#testModules()

View license
public void testModules() throws Exception {
    ModuleRootModificationUtil.addDependency(myModule, createJDomLibrary());
    final VirtualFile srcRoot = addSourceRoot(myModule, false);
    final VirtualFile testRoot = addSourceRoot(myModule, true);
    final VirtualFile output = setModuleOutput(myModule, false);
    final VirtualFile testOutput = setModuleOutput(myModule, true);
    assertClassRoots(orderEntriesForModulesList(myModule).withoutSdk(), testOutput, output, getJDomJar());
    assertSourceRoots(orderEntriesForModulesList(myModule).withoutSdk(), srcRoot, testRoot, getJDomSources());
}

26. NonProjectFileAccessTest#testAllowEditingFileInDirectory()

View license
public void testAllowEditingFileInDirectory() throws Exception {
    VirtualFile nonProjectFileDir11 = createNonProjectFile();
    File dir = new File(nonProjectFileDir11.getParent().getPath());
    VirtualFile nonProjectFileDir12 = createFileExternally(dir);
    File subDir = new File(dir, "subdir");
    subDir.mkdirs();
    VirtualFile nonProjectFileDirSubdir1 = createFileExternally(subDir);
    VirtualFile nonProjectFileDir2 = createNonProjectFile();
    typeAndCheck(nonProjectFileDir11, false);
    typeAndCheck(nonProjectFileDir12, false);
    typeAndCheck(nonProjectFileDir2, false);
    typeAndCheck(nonProjectFileDir11, NonProjectFileWritingAccessProvider.UnlockOption.UNLOCK_DIR, true);
    // affects other files in dir
    typeAndCheck(nonProjectFileDir12, true);
    typeAndCheck(nonProjectFileDirSubdir1, true);
    // doesn't affect files in other dirs
    typeAndCheck(nonProjectFileDir2, false);
}

27. GradleLibraryPresentationProvider#getSDKVersion()

View license
@NotNull
@Override
public String getSDKVersion(String path) {
    final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
    assert file != null;
    VirtualFile lib = file.findChild("lib");
    assert lib != null;
    for (VirtualFile virtualFile : lib.getChildren()) {
        final String version = getGradleJarVersion(virtualFile);
        if (version != null) {
            return version;
        }
    }
    throw new AssertionError(path);
}

28. GradlePositionManager#createGradleClassLoader()

View license
@Nullable
private ClassLoader createGradleClassLoader(@NotNull Module module) {
    String rootProjectPath = module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
    if (StringUtil.isEmpty(rootProjectPath)) {
        return null;
    }
    final VirtualFile sdkHome = myLibraryManager.getGradleHome(module, module.getProject(), rootProjectPath);
    if (sdkHome == null) {
        return null;
    }
    List<URL> urls = new ArrayList<URL>();
    final VirtualFile libDir = sdkHome.findChild("lib");
    assert libDir != null;
    for (final VirtualFile child : libDir.getChildren()) {
        if ("jar".equals(child.getExtension())) {
            urls.add(VfsUtilCore.convertToURL(child.getUrl()));
        }
    }
    return UrlClassLoader.build().urls(urls).get();
}

29. MakeUtil#getSourceRoot()

Project: consulo
Source File: MakeUtil.java
View license
public static VirtualFile getSourceRoot(CompileContext context, Module module, VirtualFile file) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    final VirtualFile root = fileIndex.getSourceRootForFile(file);
    if (root != null) {
        return root;
    }
    // try to find among roots of generated files.
    final VirtualFile[] sourceRoots = context.getSourceRoots(module);
    for (final VirtualFile sourceRoot : sourceRoots) {
        if (fileIndex.isInSourceContent(sourceRoot)) {
            // skip content source roots, need only roots for generated files
            continue;
        }
        if (VfsUtil.isAncestor(sourceRoot, file, false)) {
            return sourceRoot;
        }
    }
    return null;
}

30. PathEditor#doAdd()

Project: consulo
Source File: PathEditor.java
View license
private VirtualFile[] doAdd() {
    VirtualFile baseDir = myAddBaseDir;
    Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myComponent));
    if (baseDir == null && project != null) {
        baseDir = project.getBaseDir();
    }
    VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myComponent, project, baseDir);
    files = adjustAddedFileSet(myComponent, files);
    List<VirtualFile> added = new ArrayList<VirtualFile>(files.length);
    for (VirtualFile vFile : files) {
        if (addElement(vFile)) {
            added.add(vFile);
        }
    }
    return VfsUtil.toVirtualFileArray(added);
}

31. CopyReferenceAction#getVirtualFileFqn()

Project: consulo
Source File: CopyReferenceAction.java
View license
private static String getVirtualFileFqn(@NotNull VirtualFile virtualFile, @NotNull Project project) {
    final LogicalRoot logicalRoot = LogicalRootsManager.getLogicalRootsManager(project).findLogicalRoot(virtualFile);
    VirtualFile logicalRootFile = logicalRoot != null ? logicalRoot.getVirtualFile() : null;
    if (logicalRootFile != null && !virtualFile.equals(logicalRootFile)) {
        return ObjectUtil.assertNotNull(VfsUtilCore.getRelativePath(virtualFile, logicalRootFile, '/'));
    }
    VirtualFile outerMostRoot = null;
    VirtualFile each = virtualFile;
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    while (each != null && (each = index.getContentRootForFile(each, false)) != null) {
        outerMostRoot = each;
        each = each.getParent();
    }
    if (outerMostRoot != null && !outerMostRoot.equals(virtualFile)) {
        return ObjectUtil.assertNotNull(VfsUtilCore.getRelativePath(virtualFile, outerMostRoot, '/'));
    }
    return virtualFile.getPath();
}

32. ImportModuleAction#selectFileAndCreateWizard()

Project: consulo
Source File: ImportModuleAction.java
View license
@Nullable
public static AddModuleWizard selectFileAndCreateWizard(final Project project, @Nullable Component dialogParent, @NotNull FileChooserDescriptor descriptor, ProjectImportProvider[] providers) {
    FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, project, dialogParent);
    VirtualFile toSelect = null;
    String lastLocation = PropertiesComponent.getInstance().getValue(LAST_IMPORTED_LOCATION);
    if (lastLocation != null) {
        toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation);
    }
    VirtualFile[] files = chooser.choose(project, toSelect == null ? VirtualFile.EMPTY_ARRAY : new VirtualFile[] { toSelect });
    if (files.length == 0) {
        return null;
    }
    final VirtualFile file = files[0];
    PropertiesComponent.getInstance().setValue(LAST_IMPORTED_LOCATION, file.getPath());
    return createImportWizard(project, dialogParent, file, providers);
}

33. QualifiedNameProviders#getFileFqn()

Project: consulo
Source File: QualifiedNameProviders.java
View license
@NotNull
public static String getFileFqn(final PsiFile file) {
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) {
        return file.getName();
    }
    final Project project = file.getProject();
    final LogicalRoot logicalRoot = LogicalRootsManager.getLogicalRootsManager(project).findLogicalRoot(virtualFile);
    if (logicalRoot != null) {
        String logical = FileUtil.toSystemIndependentName(VfsUtil.virtualToIoFile(logicalRoot.getVirtualFile()).getPath());
        String path = FileUtil.toSystemIndependentName(VfsUtil.virtualToIoFile(virtualFile).getPath());
        return "/" + FileUtil.getRelativePath(logical, path, '/');
    }
    final VirtualFile contentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(virtualFile);
    if (contentRoot != null) {
        return "/" + FileUtil.getRelativePath(VfsUtil.virtualToIoFile(contentRoot), VfsUtil.virtualToIoFile(virtualFile));
    }
    return virtualFile.getPath();
}

34. ProjectBaseDirNavigationContributor#getNames()

View license
@Override
@NotNull
public String[] getNames(Project project, boolean includeNonProjectItems) {
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null)
        return ArrayUtil.EMPTY_STRING_ARRAY;
    final VirtualFile[] files = baseDir.getChildren();
    final ArrayList<String> list = new ArrayList<String>();
    for (VirtualFile file : files) {
        if (!file.isDirectory()) {
            list.add(file.getName());
        }
    }
    return ArrayUtil.toStringArray(list);
}

35. ProjectBaseDirNavigationContributor#getItemsByName()

View license
@Override
@NotNull
public NavigationItem[] getItemsByName(String name, final String pattern, Project project, boolean includeNonProjectItems) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null)
        return NavigationItem.EMPTY_ARRAY;
    final VirtualFile[] files = baseDir.getChildren();
    final ArrayList<PsiFile> list = new ArrayList<PsiFile>();
    for (VirtualFile file : files) {
        if (isEditable(file, includeNonProjectItems) && Comparing.strEqual(name, file.getName())) {
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile != null) {
                list.add(psiFile);
            }
        }
    }
    return PsiUtilCore.toPsiFileArray(list);
}

36. CloseAllEditorsButActiveAction#actionPerformed()

View license
public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
    VirtualFile selectedFile;
    final EditorWindow window = e.getData(EditorWindow.DATA_KEY);
    if (window != null) {
        window.closeAllExcept(e.getData(PlatformDataKeys.VIRTUAL_FILE));
        return;
    }
    selectedFile = fileEditorManager.getSelectedFiles()[0];
    final VirtualFile[] siblings = fileEditorManager.getSiblings(selectedFile);
    for (final VirtualFile sibling : siblings) {
        if (!Comparing.equal(selectedFile, sibling)) {
            fileEditorManager.closeFile(sibling);
        }
    }
}

37. DifferenceReverterTest#testFileDeletion()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testFileDeletion() throws Exception {
    VirtualFile f = myRoot.createChildData(this, "foo.txt");
    f.setBinaryContent(new byte[] { 123 }, -1, 4000);
    f.delete(this);
    revertLastChange();
    f = myRoot.findChild("foo.txt");
    assertNotNull(f);
    assertEquals(123, f.contentsToByteArray()[0]);
    assertEquals(4000, f.getTimeStamp());
}

38. DifferenceReverterTest#testRename()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testRename() throws Exception {
    VirtualFile f = myRoot.createChildData(this, "foo.txt");
    f.setBinaryContent(new byte[] { 123 }, -1, 4000);
    f.rename(this, "bar.txt");
    revertLastChange();
    assertNull(myRoot.findChild("bar.txt"));
    f = myRoot.findChild("foo.txt");
    assertNotNull(f);
    assertEquals(123, f.contentsToByteArray()[0]);
    assertEquals(4000, f.getTimeStamp());
}

39. DifferenceReverterTest#testRevertContentChange()

Project: consulo
Source File: DifferenceReverterTest.java
View license
public void testRevertContentChange() throws Exception {
    VirtualFile f = myRoot.createChildData(this, "foo.txt");
    f.setBinaryContent(new byte[] { 1 }, -1, 1000);
    f.setBinaryContent(new byte[] { 2 }, -1, 2000);
    revertLastChange();
    f = myRoot.findChild("foo.txt");
    assertNotNull(f);
    assertEquals(1, f.contentsToByteArray()[0]);
    assertEquals(1000, f.getTimeStamp());
}

40. RevisionsAndDiffsTest#testRevisionForRestoredDirectoryWithRestoreChildren()

Project: consulo
Source File: RevisionsAndDiffsTest.java
View license
public void testRevisionForRestoredDirectoryWithRestoreChildren() throws IOException {
    VirtualFile dir = createDirectory("dir");
    createFile("dir/f.txt");
    dir.delete(this);
    getVcs().beginChangeSet();
    dir = createDirectory("dir");
    VirtualFile f = createFile("dir/f.txt");
    getVcs().endChangeSet(null);
    List<Revision> rr = getRevisionsFor(dir);
    assertEquals(5, rr.size());
    assertEquals(1, rr.get(0).findEntry().getChildren().size());
    assertNull(rr.get(1).findEntry());
    assertEquals(1, rr.get(2).findEntry().getChildren().size());
    assertEquals(0, rr.get(3).findEntry().getChildren().size());
    assertEquals(4, getRevisionsFor(f).size());
}

41. RevisionsAndDiffsTest#testRevisionsForFileCreatedInPlaceOfRenamedOne()

Project: consulo
Source File: RevisionsAndDiffsTest.java
View license
public void testRevisionsForFileCreatedInPlaceOfRenamedOne() throws IOException {
    VirtualFile f = createFile("file1.txt", "content1");
    f.rename("file1", "file2.txt");
    VirtualFile ff = createFile("file1.txt", "content2");
    List<Revision> rr = getRevisionsFor(ff);
    assertEquals(2, rr.size());
    Entry e = rr.get(0).findEntry();
    assertEquals("file1.txt", e.getName());
    assertContent("content2", e);
    rr = getRevisionsFor(f);
    assertEquals(3, rr.size());
    e = rr.get(0).findEntry();
    assertEquals("file2.txt", e.getName());
    assertContent("content1", e);
    e = rr.get(1).findEntry();
    assertEquals("file1.txt", e.getName());
    assertContent("content1", e);
}

42. RevisionsAndDiffsTest#testGettingEntryFromRevisionInRenamedDir()

Project: consulo
Source File: RevisionsAndDiffsTest.java
View license
public void testGettingEntryFromRevisionInRenamedDir() throws IOException {
    VirtualFile dir = createDirectory("dir");
    VirtualFile f = createFile("dir/file.txt");
    dir.rename("dir", "newDir");
    setContent(f, "xxx");
    List<Revision> rr = getRevisionsFor(f);
    assertEquals(4, rr.size());
    assertEquals(myRoot.getPath() + "/newDir/file.txt", rr.get(0).findEntry().getPath());
    assertEquals(myRoot.getPath() + "/newDir/file.txt", rr.get(1).findEntry().getPath());
    assertEquals(myRoot.getPath() + "/dir/file.txt", rr.get(2).findEntry().getPath());
}

43. OutgoingChangesUtil#getVcsRootsForChanges()

Project: consulo
Source File: OutgoingChangesUtil.java
View license
public static <T extends CommittedChangeList> Collection<Pair<VcsRevisionNumber, List<T>>> getVcsRootsForChanges(final AbstractVcs vcs, final Collection<Change> changes) throws VcsException {
    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(vcs.getProject());
    final VcsOutgoingChangesProvider provider = vcs.getOutgoingChangesProvider();
    if (provider == null)
        return Collections.emptyList();
    final VirtualFile[] files = ChangesUtil.getFilesFromChanges(changes);
    final Set<VirtualFile> roots = new HashSet<VirtualFile>();
    for (VirtualFile file : files) {
        final VirtualFile root = vcsManager.getVcsRootFor(file);
        if (root != null) {
            roots.add(root);
        }
    }
    final Collection<Pair<VcsRevisionNumber, List<T>>> result = new ArrayList<Pair<VcsRevisionNumber, List<T>>>(roots.size());
    for (VirtualFile root : roots) {
        final Pair<VcsRevisionNumber, List<T>> pair = provider.getOutgoingChanges(root, true);
        result.add(pair);
    }
    return result;
}

44. AnnotateToggleAction#isEnabled()

Project: consulo
Source File: AnnotateToggleAction.java
View license
private static boolean isEnabled(final VcsContext context) {
    VirtualFile[] selectedFiles = context.getSelectedFiles();
    if (selectedFiles.length != 1) {
        return false;
    }
    VirtualFile file = selectedFiles[0];
    if (file.isDirectory())
        return false;
    Project project = context.getProject();
    if (project == null || project.isDisposed())
        return false;
    final ProjectLevelVcsManager plVcsManager = ProjectLevelVcsManager.getInstance(project);
    final BackgroundableActionEnabledHandler handler = ((ProjectLevelVcsManagerImpl) plVcsManager).getBackgroundableActionHandler(VcsBackgroundableActions.ANNOTATE);
    if (handler.isInProgress(file.getPath()))
        return false;
    final AbstractVcs vcs = plVcsManager.getVcsFor(file);
    if (vcs == null)
        return false;
    final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
    if (annotationProvider == null)
        return false;
    final FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(file);
    if (fileStatus == FileStatus.UNKNOWN || fileStatus == FileStatus.ADDED || fileStatus == FileStatus.IGNORED) {
        return false;
    }
    return hasTextEditor(file);
}

45. FileGroup#findFile()

Project: ideavim
Source File: FileGroup.java
View license
@Nullable
private VirtualFile findFile(@NotNull VirtualFile root, @NotNull String filename) {
    VirtualFile res = root.findFileByRelativePath(filename);
    if (res != null) {
        return res;
    }
    VirtualFile[] children = root.getChildren();
    for (VirtualFile child : children) {
        if (child.isDirectory()) {
            res = findFile(child, filename);
            if (res != null) {
                return res;
            }
        } else if (child.getName().equals(filename)) {
            return child;
        }
    }
    return null;
}

46. MultipleRootsMoveDestination#verify()

View license
public String verify(PsiFile source) {
    VirtualFile virtualFile = source.getVirtualFile();
    if (virtualFile.isDirectory()) {
        virtualFile = virtualFile.getParent();
        LOG.assertTrue(virtualFile.isDirectory());
    }
    final VirtualFile sourceRootForFile = myFileIndex.getSourceRootForFile(virtualFile);
    if (sourceRootForFile == null) {
        return "";
    }
    return checkCanCreateInSourceRoot(sourceRootForFile);
}

47. AdvHighlightingTest#testSameClassesInSourceAndLib()

View license
public void testSameClassesInSourceAndLib() throws Exception {
    String path = PathManagerEx.getTestDataPath() + BASE_PATH + "/" + getTestName(true);
    VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
    assert root != null : path;
    loadAllModulesUnder(root);
    configureByExistingFile(root.findFileByRelativePath("src/ppp/SomeClass.java"));
    PsiField field = ((PsiJavaFile) myFile).getClasses()[0].findFieldByName("f", false);
    assert field != null;
    PsiClass aClass = ((PsiClassType) field.getType()).resolve();
    assert aClass != null;
    assertEquals("ppp.BadClass", aClass.getQualifiedName());
    //lies in source
    VirtualFile vFile1 = myFile.getVirtualFile();
    VirtualFile vFile2 = aClass.getContainingFile().getVirtualFile();
    assert vFile1 != null;
    assert vFile2 != null;
    assertEquals(vFile1.getParent(), vFile2.getParent());
}

48. LossyEncodingTest#testDetectWrongEncoding0()

View license
public void testDetectWrongEncoding0() throws Exception {
    String threeNotoriousRussianLetters = "???";
    configureByText(FileTypes.PLAIN_TEXT, threeNotoriousRussianLetters);
    VirtualFile virtualFile = getFile().getVirtualFile();
    final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    WriteCommandAction.runWriteCommandAction(getProject(), () -> {
        document.insertString(0, " ");
        document.deleteString(0, 1);
    });
    assertTrue(FileDocumentManager.getInstance().isDocumentUnsaved(document));
    assertEquals(CharsetToolkit.UTF8_CHARSET, virtualFile.getCharset());
    Charset WINDOWS_1251 = Charset.forName("windows-1251");
    virtualFile.setCharset(WINDOWS_1251);
    FileDocumentManager.getInstance().saveAllDocuments();
    assertEquals(WINDOWS_1251, virtualFile.getCharset());
    assertEquals(threeNotoriousRussianLetters, new String(virtualFile.contentsToByteArray(), WINDOWS_1251));
    virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
    doHighlighting();
    List<HighlightInfo> infos = DaemonCodeAnalyzerEx.getInstanceEx(getProject()).getFileLevelHighlights(getProject(), getFile());
    HighlightInfo info = assertOneElement(infos);
    assertEquals("File was loaded in the wrong encoding: 'UTF-8'", info.getDescription());
}

49. FindManagerTest#testNonRecursiveDirectory()

View license
public void testNonRecursiveDirectory() throws Exception {
    VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTempDirectory());
    addSourceContentToRoots(myModule, root);
    VirtualFile foo = createChildDirectory(root, "foo");
    VirtualFile bar = createChildDirectory(foo, "bar");
    createFile(myModule, root, "A.txt", "goo doo");
    createFile(myModule, foo, "A.txt", "goo doo");
    createFile(myModule, bar, "A.txt", "doo goo");
    FindModel findModel = FindManagerTestUtils.configureFindModel("done");
    findModel.setProjectScope(false);
    findModel.setDirectoryName(foo.getPath());
    findModel.setStringToFind("doo");
    findModel.setWithSubdirectories(true);
    assertSize(2, findUsages(findModel));
    findModel.setWithSubdirectories(false);
    assertSize(1, findUsages(findModel));
}

50. PsiChangeTrackerTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    final VirtualFile testRoot = getTestRoot();
    final VirtualFile child = testRoot.findChild("PsiChangesTest.java");
    assert child != null : "Can't find PsiChangesTest.java";
    final PsiFile original = getPsiManager().findFile(child);
    assert original != null : "Can't create PsiFile from VirtualFile " + child.getName();
    myOriginalFile = original;
    final VirtualFile changedFile = testRoot.findChild("PsiChangesTest_changed.java");
    assert changedFile != null : "Can't find PsiChangesTest_changed.java";
    myChangedFile = PsiFileFactory.getInstance(myProject).createFileFromText(LoadTextUtil.loadText(changedFile), myOriginalFile);
    assert myChangedFile != null : "Can't create PsiFile from " + changedFile.getPath();
}

51. AddClassToFileTest#testFileModified()

View license
public void testFileModified() throws Exception {
    VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, myFilesToDelete);
    VirtualFile pkg = createChildDirectory(root, "foo");
    PsiDirectory dir = myPsiManager.findDirectory(pkg);
    assertNotNull(dir);
    String text = "package foo;\n\nclass A {}";
    PsiElement created = ApplicationManager.getApplication().runWriteAction(new Computable<PsiElement>() {

        @Override
        public PsiElement compute() {
            return dir.add(PsiFileFactory.getInstance(getProject()).createFileFromText("A.java", JavaFileType.INSTANCE, text));
        }
    });
    VirtualFile virtualFile = created.getContainingFile().getVirtualFile();
    assertNotNull(virtualFile);
    String fileText = LoadTextUtil.loadText(virtualFile).toString();
    assertEquals(text, fileText);
    Document doc = FileDocumentManager.getInstance().getDocument(virtualFile);
    assertNotNull(doc);
    assertFalse(FileDocumentManager.getInstance().isDocumentUnsaved(doc));
    assertFalse(FileDocumentManager.getInstance().isFileModified(virtualFile));
}

52. MiscPsiTest#testCopyBinaryFile()

Project: intellij-community
Source File: MiscPsiTest.java
View license
public void testCopyBinaryFile() throws Exception {
    VirtualFile vFile = myFixture.addFileToProject("Test.xxx", "").getVirtualFile();
    final byte[] bytes = { 12, 34, 56, 78, 90, 45, 83, 0x22, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xee };
    vFile.setBinaryContent(bytes);
    VirtualFile vDir = myFixture.getTempDirFixture().findOrCreateDir("dir");
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    PsiFile file = getPsiManager().findFile(vFile);
    assertInstanceOf(file, PsiBinaryFile.class);
    PsiDirectory dir = getPsiManager().findDirectory(vDir);
    PsiFile fileCopy = (PsiFile) file.copy();
    fileCopy = (PsiFile) fileCopy.setName("NewTest.xxx");
    PsiFile newFile = (PsiFile) dir.add(fileCopy);
    if (!(newFile instanceof PsiBinaryFile)) {
        System.out.println(newFile.getVirtualFile().getFileType());
        System.out.println(newFile.getFileType());
        System.out.println(newFile.getText());
    }
    assertInstanceOf(newFile, PsiBinaryFile.class);
    assertOrderedEquals(newFile.getVirtualFile().contentsToByteArray(), bytes);
}

53. MiscPsiTest#testSCR5929()

Project: intellij-community
Source File: MiscPsiTest.java
View license
public void testSCR5929() throws Exception {
    String text = "class A{ /** @see a.B */ }";
    VirtualFile vFileA = myFixture.addFileToProject("A.java", text).getVirtualFile();
    VirtualFile dir = myFixture.getTempDirFixture().findOrCreateDir("a");
    VirtualFile vFileB = dir.createChildData(null, "B.java");
    text = "class B{}";
    VfsUtil.saveText(vFileB, text);
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    PsiFile fileA = getPsiManager().findFile(vFileA);
    PsiJavaFile fileACopy = (PsiJavaFile) fileA.copy();
    PsiClass aClass = fileACopy.getClasses()[0];
    aClass.setName("A2");
    fileA.getContainingDirectory().add(fileACopy);
}

54. CopyClassTest#doPackageCopy()

View license
private void doPackageCopy() throws Exception {
    String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true);
    String rootBefore = root + "/before";
    PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
    VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
    final VirtualFile targetVDir = rootDir.findChild("p2");
    final PsiDirectory sourceP1Dir = myPsiManager.findDirectory(rootDir.findChild("p1"));
    final PsiDirectory targetP2Dir = myPsiManager.findDirectory(targetVDir);
    new CopyClassesHandler().doCopy(new PsiElement[] { sourceP1Dir }, targetP2Dir);
    String rootAfter = root + "/after";
    VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
    myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
    PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}

55. CopyTest#testMultipleClasses()

Project: intellij-community
Source File: CopyTest.java
View license
public void testMultipleClasses() throws Exception {
    String rootBefore = getRoot();
    PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
    final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
    final PsiClass aClass = myJavaFacade.findClass("pack1.Klass");
    assertNotNull(aClass);
    final PsiFile containingFile = aClass.getContainingFile();
    assertTrue(CopyHandler.canCopy(new PsiElement[] { containingFile }));
    assertFalse(CopyHandler.canClone(new PsiElement[] { containingFile }));
    PsiPackage pack2 = myJavaFacade.findPackage("pack2");
    final PsiDirectory targetDirectory = pack2.getDirectories()[0];
    CopyHandler.doCopy(new PsiElement[] { containingFile }, targetDirectory);
    VirtualFile fileAfter = root.findFileByRelativePath("pack2/Klass.java");
    VirtualFile fileExpected = root.findFileByRelativePath("pack2/Klass.expected.java");
    PlatformTestUtil.assertFilesEqual(fileExpected, fileAfter);
}

56. ModuleScopesTest#testTestOnlyModuleDependency()

View license
public void testTestOnlyModuleDependency() throws Exception {
    Module moduleA = createModule("a.iml", StdModuleTypes.JAVA);
    Module moduleB = addDependentModule(moduleA, DependencyScope.TEST);
    VirtualFile classB = myFixture.createFile("b/Test.java", "public class Test { }");
    assertTrue(moduleA.getModuleWithDependenciesAndLibrariesScope(true).contains(classB));
    assertFalse(moduleA.getModuleWithDependenciesAndLibrariesScope(false).contains(classB));
    assertFalse(moduleA.getModuleWithDependenciesAndLibrariesScope(false).isSearchInModuleContent(moduleB));
    final VirtualFile[] compilationClasspath = getCompilationClasspath(moduleA);
    assertEquals(1, compilationClasspath.length);
    final VirtualFile[] productionCompilationClasspath = getProductionCompileClasspath(moduleA);
    assertEmpty(productionCompilationClasspath);
    final PathsList pathsList = OrderEnumerator.orderEntries(moduleA).recursively().getPathsList();
    assertEquals(1, pathsList.getPathList().size());
    final PathsList pathsListWithoutTests = OrderEnumerator.orderEntries(moduleA).productionOnly().recursively().getPathsList();
    assertEquals(0, pathsListWithoutTests.getPathList().size());
}

57. ModuleScopesTest#testTestOnlyLibraryDependency()

View license
public void testTestOnlyLibraryDependency() throws IOException {
    Module m = createModule("a.iml", StdModuleTypes.JAVA);
    addLibrary(m, DependencyScope.TEST);
    VirtualFile libraryClass = myFixture.createFile("lib/Test.class");
    assertTrue(m.getModuleWithDependenciesAndLibrariesScope(true).contains(libraryClass));
    assertFalse(m.getModuleWithDependenciesAndLibrariesScope(false).contains(libraryClass));
    final VirtualFile[] compilationClasspath = getCompilationClasspath(m);
    assertEquals(1, compilationClasspath.length);
    final VirtualFile[] productionCompilationClasspath = getProductionCompileClasspath(m);
    assertEmpty(productionCompilationClasspath);
}

58. JsonSchemaCrossReferencesTest#testRefreshSchemaCompletionSimpleVariant()

View license
public void testRefreshSchemaCompletionSimpleVariant() throws Exception {
    configureByFiles(null, BASE_PATH + "/baseCompletion.json", BASE_PATH + "/baseProperties.json");
    String moduleDir = null;
    VirtualFile moduleFile = null;
    VirtualFile[] children = getProject().getBaseDir().getChildren();
    for (VirtualFile child : children) {
        if (child.isDirectory()) {
            moduleDir = child.getName();
            moduleFile = child;
            break;
        }
    }
    Assert.assertNotNull(moduleDir);
    final JsonSchemaMappingsProjectConfiguration instance = JsonSchemaMappingsProjectConfiguration.getInstance(getProject());
    final JsonSchemaMappingsConfigurationBase.SchemaInfo base = new JsonSchemaMappingsConfigurationBase.SchemaInfo("base", "/" + moduleDir + "/baseProperties.json", false, Collections.singletonList(new JsonSchemaMappingsConfigurationBase.Item("*.json", true, false)));
    instance.addSchema(base);
    testSchemaCompletion(moduleFile, "baseProperties.json");
    instance.removeSchema(base);
}

59. JdkUtil#getJdkMainAttribute()

Project: intellij-community
Source File: JdkUtil.java
View license
/**
   * @return the specified attribute of the JDK (examines rt.jar) or null if cannot determine the value
   */
@Nullable
public static String getJdkMainAttribute(@NotNull Sdk jdk, Attributes.Name attribute) {
    VirtualFile homeDirectory = jdk.getHomeDirectory();
    if (homeDirectory == null)
        return null;
    // JDK
    VirtualFile rtJar = homeDirectory.findFileByRelativePath("jre/lib/rt.jar");
    // JRE
    if (rtJar == null)
        rtJar = homeDirectory.findFileByRelativePath("lib/rt.jar");
    // IBM JDK
    if (rtJar == null)
        rtJar = homeDirectory.findFileByRelativePath("jre/lib/vm.jar");
    // Apple JDK
    if (rtJar == null)
        rtJar = homeDirectory.findFileByRelativePath("../Classes/classes.jar");
    if (rtJar == null) {
        String versionString = jdk.getVersionString();
        if (versionString != null) {
            final int start = versionString.indexOf("\"");
            final int end = versionString.lastIndexOf("\"");
            versionString = start >= 0 && (end > start) ? versionString.substring(start + 1, end) : null;
        }
        return versionString;
    }
    VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(rtJar);
    return jarRoot != null ? getJarMainAttribute(jarRoot, attribute) : null;
}

60. CopyReferenceAction#getVirtualFileFqn()

View license
private static String getVirtualFileFqn(@NotNull VirtualFile virtualFile, @NotNull Project project) {
    final LogicalRoot logicalRoot = LogicalRootsManager.getLogicalRootsManager(project).findLogicalRoot(virtualFile);
    VirtualFile logicalRootFile = logicalRoot != null ? logicalRoot.getVirtualFile() : null;
    if (logicalRootFile != null && !virtualFile.equals(logicalRootFile)) {
        return ObjectUtils.assertNotNull(VfsUtilCore.getRelativePath(virtualFile, logicalRootFile, '/'));
    }
    VirtualFile outerMostRoot = null;
    VirtualFile each = virtualFile;
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    while (each != null && (each = index.getContentRootForFile(each, false)) != null) {
        outerMostRoot = each;
        each = each.getParent();
    }
    if (outerMostRoot != null && !outerMostRoot.equals(virtualFile)) {
        return ObjectUtils.assertNotNull(VfsUtilCore.getRelativePath(virtualFile, outerMostRoot, '/'));
    }
    return virtualFile.getPath();
}

61. ProjectBaseDirNavigationContributor#getNames()

View license
@Override
@NotNull
public String[] getNames(Project project, boolean includeNonProjectItems) {
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null)
        return ArrayUtil.EMPTY_STRING_ARRAY;
    final VirtualFile[] files = baseDir.getChildren();
    final ArrayList<String> list = new ArrayList<String>();
    for (VirtualFile file : files) {
        if (!file.isDirectory()) {
            list.add(file.getName());
        }
    }
    return ArrayUtil.toStringArray(list);
}

62. ProjectBaseDirNavigationContributor#getItemsByName()

View license
@Override
@NotNull
public NavigationItem[] getItemsByName(String name, final String pattern, Project project, boolean includeNonProjectItems) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null)
        return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY;
    final VirtualFile[] files = baseDir.getChildren();
    final ArrayList<PsiFile> list = new ArrayList<PsiFile>();
    for (VirtualFile file : files) {
        if (isEditable(file, includeNonProjectItems) && Comparing.strEqual(name, file.getName())) {
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile != null) {
                list.add(psiFile);
            }
        }
    }
    return PsiUtilCore.toPsiFileArray(list);
}

63. CloseAllEditorsButActiveAction#actionPerformed()

View license
public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
    VirtualFile selectedFile;
    final EditorWindow window = e.getData(EditorWindow.DATA_KEY);
    if (window != null) {
        window.closeAllExcept(e.getData(CommonDataKeys.VIRTUAL_FILE));
        return;
    }
    selectedFile = fileEditorManager.getSelectedFiles()[0];
    final VirtualFile[] siblings = fileEditorManager.getSiblings(selectedFile);
    for (final VirtualFile sibling : siblings) {
        if (!Comparing.equal(selectedFile, sibling)) {
            fileEditorManager.closeFile(sibling);
        }
    }
}

64. PatchCreatorTest#testDirectoryRename()

View license
public void testDirectoryRename() throws Exception {
    VirtualFile dir = createChildDirectory(myRoot, "dir1");
    createChildData(dir, "f.txt");
    rename(dir, "dir2");
    createPatchBetweenRevisions(1, 0);
    rename(dir, "dir1");
    applyPatch();
    VirtualFile afterDir1 = myRoot.findChild("dir1");
    VirtualFile afterDir2 = myRoot.findChild("dir2");
    assertNotNull(afterDir1);
    assertNotNull(afterDir2);
    assertNull(afterDir1.findChild("f.txt"));
    assertNotNull(afterDir2.findChild("f.txt"));
}

65. DifferenceReverterTest#testDirDeletion()

View license
public void testDirDeletion() throws Exception {
    VirtualFile dir = createChildDirectory(myRoot, "dir");
    VirtualFile subdir = createChildDirectory(dir, "subdir");
    VirtualFile f = createChildData(subdir, "foo.txt");
    int modificationStamp = -1;
    setBinaryContent(f, new byte[] { 123 }, modificationStamp, 4000, this);
    delete(dir);
    revertLastChange();
    dir = myRoot.findChild("dir");
    subdir = dir.findChild("subdir");
    f = subdir.findChild("foo.txt");
    assertNotNull(f);
    assertEquals(123, f.contentsToByteArray()[0]);
    assertEquals(4000, f.getTimeStamp());
}

66. DifferenceReverterTest#testMovement()

View license
public void testMovement() throws Exception {
    VirtualFile dir1 = createChildDirectory(myRoot, "dir1");
    VirtualFile dir2 = createChildDirectory(myRoot, "dir2");
    VirtualFile f = createChildData(dir1, "foo.txt");
    int modificationStamp = -1;
    setBinaryContent(f, new byte[] { 123 }, modificationStamp, 4000, this);
    move(f, dir2);
    revertLastChange();
    assertNull(dir2.findChild("foo.txt"));
    f = dir1.findChild("foo.txt");
    assertNotNull(f);
    assertEquals(123, f.contentsToByteArray()[0]);
    assertEquals(4000, f.getTimeStamp());
}

67. DifferenceReverterTest#testRevertingMoveFromOldRevisionsWhenDirDoesNotExists()

View license
public void testRevertingMoveFromOldRevisionsWhenDirDoesNotExists() throws Exception {
    VirtualFile dir1 = createChildDirectory(myRoot, "dir1");
    VirtualFile dir2 = createChildDirectory(myRoot, "dir2");
    VirtualFile f = createChildData(dir1, "foo.txt");
    move(f, dir2);
    delete(dir1);
    delete(dir2);
    revertChange(2);
    dir1 = myRoot.findChild("dir1");
    assertNotNull(dir1);
    assertNull(myRoot.findChild("dir2"));
    assertNotNull(dir1.findChild("foo.txt"));
}

68. NonProjectFileAccessTest#testDoNotLockCreatedAndCopiedFiles()

View license
public void testDoNotLockCreatedAndCopiedFiles() throws Exception {
    VirtualFile nonProjectFile = createNonProjectFile();
    typeAndCheck(nonProjectFile, false);
    final VirtualFile[] createdNonProject = new VirtualFile[1];
    final VirtualFile[] copiedNonProject = new VirtualFile[1];
    new WriteAction<Object>() {

        @Override
        protected void run(@NotNull Result<Object> result) throws Throwable {
            createdNonProject[0] = nonProjectFile.getParent().createChildData(this, "createdNonProject.txt");
            copiedNonProject[0] = nonProjectFile.copy(this, nonProjectFile.getParent(), "copiedNonProject.txt");
            myCreatedFiles.add(createdNonProject[0]);
            myCreatedFiles.add(copiedNonProject[0]);
        }
    }.execute();
    typeAndCheck(createdNonProject[0], true);
    typeAndCheck(copiedNonProject[0], true);
    // original is still locked 
    typeAndCheck(nonProjectFile, false);
}

69. NonProjectFileAccessTest#testAllowEditingInAllFiles()

View license
public void testAllowEditingInAllFiles() throws Exception {
    VirtualFile nonProjectFile1 = createNonProjectFile();
    VirtualFile nonProjectFile2 = createNonProjectFile();
    VirtualFile nonProjectFile3 = createNonProjectFile();
    typeAndCheck(nonProjectFile1, false);
    typeAndCheck(nonProjectFile2, false);
    typeAndCheck(nonProjectFile3, false);
    typeAndCheck(nonProjectFile1, NonProjectFileWritingAccessProvider.UnlockOption.UNLOCK_ALL, true);
    // affects other files
    typeAndCheck(nonProjectFile2, true);
    typeAndCheck(nonProjectFile3, true);
}

70. OutgoingChangesUtil#getVcsRootsForChanges()

View license
public static <T extends CommittedChangeList> Collection<Pair<VcsRevisionNumber, List<T>>> getVcsRootsForChanges(final AbstractVcs vcs, final Collection<Change> changes) throws VcsException {
    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(vcs.getProject());
    final VcsOutgoingChangesProvider provider = vcs.getOutgoingChangesProvider();
    if (provider == null)
        return Collections.emptyList();
    final VirtualFile[] files = ChangesUtil.getFilesFromChanges(changes);
    final Set<VirtualFile> roots = new HashSet<VirtualFile>();
    for (VirtualFile file : files) {
        final VirtualFile root = vcsManager.getVcsRootFor(file);
        if (root != null) {
            roots.add(root);
        }
    }
    final Collection<Pair<VcsRevisionNumber, List<T>>> result = new ArrayList<Pair<VcsRevisionNumber, List<T>>>(roots.size());
    for (VirtualFile root : roots) {
        final Pair<VcsRevisionNumber, List<T>> pair = provider.getOutgoingChanges(root, true);
        result.add(pair);
    }
    return result;
}

71. EclipseVarsTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    final File testRoot = new File(PluginPathManager.getPluginHomePath("eclipse") + "/testData", getRelativeTestPath());
    assertTrue(testRoot.getAbsolutePath(), testRoot.isDirectory());
    final File currentTestRoot = new File(testRoot, getTestName(true));
    assertTrue(currentTestRoot.getAbsolutePath(), currentTestRoot.isDirectory());
    final String tempPath = getProject().getBaseDir().getPath();
    final File tempDir = new File(tempPath);
    VirtualFile vTestRoot = LocalFileSystem.getInstance().findFileByIoFile(currentTestRoot);
    copyDirContentsTo(vTestRoot, getProject().getBaseDir());
    final VirtualFile virtualTestDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir);
    assertNotNull(tempDir.getAbsolutePath(), virtualTestDir);
    virtualTestDir.refresh(false, true);
    PathMacros.getInstance().setMacro(VARIABLE, new File(tempPath, VARIABLE + "idea").getPath());
    PathMacros.getInstance().setMacro(SRCVARIABLE, new File(tempPath, SRCVARIABLE + "idea").getPath());
}

72. GitUpperDirectorySearchTest#testDirFinding()

View license
@Test
public void testDirFinding() {
    final String dirName = "somedir";
    final File file = new File(myProjectFixture.getProject().getBaseDir().getPath(), dirName);
    FileUtil.delete(file);
    Assert.assertTrue(file.mkdir(), "can't create: " + file.getAbsolutePath());
    final File childDir = new File(file, "and/a/path/to");
    Assert.assertTrue(childDir.mkdirs(), "can't create: " + childDir.getAbsolutePath());
    final VirtualFile dir = myLocalFileSystem.refreshAndFindFileByIoFile(file);
    final VirtualFile childFile = myLocalFileSystem.refreshAndFindFileByIoFile(childDir);
    Assert.assertNotNull(dir);
    Assert.assertNotNull(childFile);
    final VirtualFile result = VcsFileUtil.getPossibleBase(childFile, dirName);
    Assert.assertEquals(result, dir);
}

73. GitUpperDirectorySearchTest#testLongPattern()

View license
@Test
public void testLongPattern() throws Exception {
    final String dirName = SystemInfo.isFileSystemCaseSensitive ? "somedir/long/path" : "somEdir/lonG/path";
    final File file = new File(myProjectFixture.getProject().getBaseDir().getPath(), "somedir");
    FileUtil.delete(file);
    Assert.assertTrue(file.mkdir(), "can't create: " + file.getAbsolutePath());
    final File childDir = new File(file, "long/path/and/a/path/to");
    Assert.assertTrue(childDir.mkdirs(), "can't create: " + childDir.getAbsolutePath());
    final File a = new File(childDir, "a.txt");
    Assert.assertTrue(a.createNewFile(), "can't create: " + a.getAbsolutePath());
    final VirtualFile dir = myLocalFileSystem.refreshAndFindFileByIoFile(file);
    final VirtualFile childFile = myLocalFileSystem.refreshAndFindFileByIoFile(a);
    Assert.assertNotNull(dir);
    Assert.assertNotNull(childFile);
    final VirtualFile result = VcsFileUtil.getPossibleBase(childFile, dirName.split("/"));
    Assert.assertEquals(result, dir);
}

74. GitUpperDirectorySearchTest#testLongRepeatedPattern()

View license
@Test
public void testLongRepeatedPattern() throws Exception {
    final String dirName = SystemInfo.isFileSystemCaseSensitive ? "somedir/long/path" : "somEdir/lonG/path";
    final File file = new File(myProjectFixture.getProject().getBaseDir().getPath(), "somedir");
    FileUtil.delete(file);
    Assert.assertTrue(file.mkdir(), "can't create: " + file.getAbsolutePath());
    final File childDir = new File(file, "long/path/and/a/path/path/path/to/long/path");
    Assert.assertTrue(childDir.mkdirs(), "can't create: " + childDir.getAbsolutePath());
    final File a = new File(childDir, "a.txt");
    Assert.assertTrue(a.createNewFile(), "can't create: " + a.getAbsolutePath());
    final VirtualFile dir = myLocalFileSystem.refreshAndFindFileByIoFile(file);
    final VirtualFile childFile = myLocalFileSystem.refreshAndFindFileByIoFile(a);
    Assert.assertNotNull(dir);
    Assert.assertNotNull(childFile);
    final VirtualFile result = VcsFileUtil.getPossibleBase(childFile, dirName.split("/"));
    Assert.assertEquals(result, dir);
}

75. SdkHomeSettings#calcRoots()

View license
private static List<VirtualFile> calcRoots(@Nullable VirtualFile home) {
    if (home == null) {
        return Collections.emptyList();
    }
    final VirtualFile lib = home.findChild("lib");
    if (lib == null) {
        return Collections.emptyList();
    }
    List<VirtualFile> result = new ArrayList<VirtualFile>();
    for (VirtualFile file : lib.getChildren()) {
        if ("jar".equals(file.getExtension())) {
            ContainerUtil.addIfNotNull(StandardFileSystems.getJarRootForLocalFile(file), result);
        }
    }
    return result;
}

76. MvcFramework#findAppDirectory()

View license
@Nullable
public VirtualFile findAppDirectory(@Nullable PsiElement element) {
    if (element == null)
        return null;
    PsiFile containingFile = element.getContainingFile().getOriginalFile();
    VirtualFile file = containingFile.getVirtualFile();
    if (file == null)
        return null;
    ProjectFileIndex index = ProjectRootManager.getInstance(containingFile.getProject()).getFileIndex();
    VirtualFile root = index.getContentRootForFile(file);
    if (root == null)
        return null;
    return root.findChild(getApplicationDirectoryName());
}

77. MvcFramework#addAvailableScripts()

View license
public static void addAvailableScripts(final Collection<String> result, @Nullable final VirtualFile root) {
    if (root == null || !root.isDirectory()) {
        return;
    }
    final VirtualFile scripts = root.findChild("scripts");
    if (scripts == null || !scripts.isDirectory()) {
        return;
    }
    for (VirtualFile child : scripts.getChildren()) {
        if (isScriptFile(child)) {
            result.add(GroovyNamesUtil.camelToSnake(child.getNameWithoutExtension()));
        }
    }
}

78. GroovyScriptRunner#findGroovyJar()

View license
@Nullable
protected static VirtualFile findGroovyJar(@NotNull Module module) {
    final VirtualFile[] files = OrderEnumerator.orderEntries(module).getAllLibrariesAndSdkClassesRoots();
    for (VirtualFile root : files) {
        if (GroovyConfigUtils.GROOVY_JAR_PATTERN.matcher(root.getName()).matches() || GroovyConfigUtils.matchesGroovyAll(root.getName())) {
            return root;
        }
    }
    for (VirtualFile file : files) {
        if (file.getName().contains("groovy") && "jar".equals(file.getExtension())) {
            return file;
        }
    }
    return null;
}

79. HgMoveTest#testMoveFilesUnderFolder()

Project: intellij-community
Source File: HgMoveTest.java
View license
@Test
public void testMoveFilesUnderFolder() throws Exception {
    VirtualFile parent1 = createDirInCommand(myWorkingCopyDir, "com");
    VirtualFile dir = createDirInCommand(parent1, "zzz");
    createFileInCommand(dir, "a.txt", "new file content");
    runHgOnProjectRepo("commit", "-m", "added file");
    VirtualFile parent2 = createDirInCommand(myWorkingCopyDir, "org");
    moveFileInCommand(dir, parent2);
    verify(runHgOnProjectRepo("status"), HgTestOutputParser.added("org", "zzz", "a.txt"), HgTestOutputParser.removed("com", "zzz", "a.txt"));
}

80. HgMoveTest#testMoveUnversionedFile()

Project: intellij-community
Source File: HgMoveTest.java
View license
@Test
public void testMoveUnversionedFile() throws Exception {
    VirtualFile parent1 = createDirInCommand(myWorkingCopyDir, "com");
    File unversionedFile = new File(parent1.getPath(), "a.txt");
    VirtualFile file = makeFile(unversionedFile);
    verify(runHgOnProjectRepo("status"), HgTestOutputParser.unknown("com", "a.txt"));
    VirtualFile parent2 = createDirInCommand(myWorkingCopyDir, "org");
    moveFileInCommand(file, parent2);
    verify(runHgOnProjectRepo("status"), HgTestOutputParser.unknown("org", "a.txt"));
}

81. MavenParentRelativePathConverter#fromString()

View license
@Override
public PsiFile fromString(@Nullable @NonNls String s, ConvertContext context) {
    if (StringUtil.isEmptyOrSpaces(s))
        return null;
    VirtualFile contextFile = context.getFile().getVirtualFile();
    if (contextFile == null)
        return null;
    VirtualFile f = contextFile.getParent().findFileByRelativePath(s);
    if (f == null)
        return null;
    if (f.isDirectory())
        f = f.findChild(MavenConstants.POM_XML);
    if (f == null)
        return null;
    return context.getPsiManager().findFile(f);
}

82. MavenProjectsTreeReadingTest#testAddingProjectsOnUpdateAllWhenManagedFilesChanged()

View license
public void testAddingProjectsOnUpdateAllWhenManagedFilesChanged() throws Exception {
    VirtualFile m1 = createModulePom("m1", "<groupId>test</groupId>" + "<artifactId>m1</artifactId>" + "<version>1</version>");
    VirtualFile m2 = createModulePom("m2", "<groupId>test</groupId>" + "<artifactId>m2</artifactId>" + "<version>1</version>");
    VirtualFile m3 = createModulePom("m3", "<groupId>test</groupId>" + "<artifactId>m3</artifactId>" + "<version>1</version>");
    updateAll(m1, m2);
    assertEquals(2, myTree.getRootProjects().size());
    updateAll(m1, m2, m3);
    assertEquals(3, myTree.getRootProjects().size());
}

83. MavenProjectsTreeReadingTest#testDeletingProjectsOnUpdateAllWhenManagedFilesChanged()

View license
public void testDeletingProjectsOnUpdateAllWhenManagedFilesChanged() throws Exception {
    VirtualFile m1 = createModulePom("m1", "<groupId>test</groupId>" + "<artifactId>m1</artifactId>" + "<version>1</version>");
    VirtualFile m2 = createModulePom("m2", "<groupId>test</groupId>" + "<artifactId>m2</artifactId>" + "<version>1</version>");
    VirtualFile m3 = createModulePom("m3", "<groupId>test</groupId>" + "<artifactId>m3</artifactId>" + "<version>1</version>");
    updateAll(m1, m2, m3);
    assertEquals(3, myTree.getRootProjects().size());
    updateAll(m1, m2);
    assertEquals(2, myTree.getRootProjects().size());
}

84. IgnoredFilesTest#testDirIsIgnored()

View license
@Test
public void testDirIsIgnored() throws Exception {
    //final String dirPath1 = myClientRoot.getPath() + "/a";
    final File dir = new File(myClientRoot, "a");
    dir.mkdir();
    final File innerDir = new File(dir, "innerDir");
    innerDir.mkdir();
    final File file1 = new File(innerDir, "file1");
    final File file2 = new File(innerDir, "file2");
    file1.createNewFile();
    file2.createNewFile();
    final VirtualFile innerVf = myLocalFileSystem.refreshAndFindFileByIoFile(innerDir);
    final VirtualFile vf1 = myLocalFileSystem.refreshAndFindFileByIoFile(file1);
    final VirtualFile vf2 = myLocalFileSystem.refreshAndFindFileByIoFile(file2);
    final IgnoredFileBean ignoredFileBean = IgnoredBeanFactory.ignoreUnderDirectory(FileUtil.toSystemIndependentName(dir.getPath()), myProject);
    myChangeListManager.addFilesToIgnore(ignoredFileBean);
    dirty();
    assertFoundAndIgnored(innerVf);
    assertFoundAndIgnored(vf1);
    assertFoundAndIgnored(vf2);
}

85. SvnCommittedViewTest#testAdd()

View license
@Test
public void testAdd() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);
    final VirtualFile d1 = createDirInCommand(myWorkingCopyDir, "d1");
    final VirtualFile f11 = createFileInCommand(d1, "f11.txt", "123\n456");
    final VirtualFile f12 = createFileInCommand(d1, "f12.txt", "----");
    // r1, addition without history
    checkin();
    final SvnVcs vcs = SvnVcs.getInstance(myProject);
    vcs.invokeRefreshSvnRoots();
    final CommittedChangesProvider<SvnChangeList, ChangeBrowserSettings> committedChangesProvider = vcs.getCommittedChangesProvider();
    final List<SvnChangeList> changeListList = committedChangesProvider.getCommittedChanges(committedChangesProvider.createDefaultSettings(), new SvnRepositoryLocation(myRepoUrl), 0);
    checkList(changeListList, 1, new Data[] { new Data(absPath(f11), FileStatus.ADDED, null), new Data(absPath(f12), FileStatus.ADDED, null), new Data(absPath(d1), FileStatus.ADDED, null) });
}

86. SvnRenameTest#testUndoMovePackage()

View license
// IDEADEV-19364
@Test
public void testUndoMovePackage() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile parent1 = createDirInCommand(myWorkingCopyDir, "parent1");
    final VirtualFile parent2 = createDirInCommand(myWorkingCopyDir, "parent2");
    final VirtualFile child = createDirInCommand(parent1, "child");
    createFileInCommand(child, "a.txt", "a");
    checkin();
    moveFileInCommand(child, parent2);
    undo();
    final File childPath = new File(parent1.getPath(), "child");
    Assert.assertTrue(childPath.exists());
    Assert.assertTrue(new File(childPath, "a.txt").exists());
}

87. SvnRenameTest#testUndoMoveCommittedPackage()

View license
// IDEADEV-19336
@Test
public void testUndoMoveCommittedPackage() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);
    final VirtualFile parent1 = createDirInCommand(myWorkingCopyDir, "parent1");
    final VirtualFile parent2 = createDirInCommand(myWorkingCopyDir, "parent2");
    final VirtualFile child = createDirInCommand(parent1, "child");
    createFileInCommand(child, "a.txt", "a");
    checkin();
    moveFileInCommand(child, parent2);
    checkin();
    undo();
    verifySorted(runSvn("status"), "A + parent1" + File.separatorChar + "child", "D parent2" + File.separatorChar + "child", "D parent2" + File.separatorChar + "child" + File.separatorChar + "a.txt");
}

88. SvnRenameTest#testMoveToUnversioned()

View license
@Test
public void testMoveToUnversioned() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile file = createFileInCommand(myWorkingCopyDir, "a.txt", "A");
    final VirtualFile child = moveToNewPackage(file, "child");
    verifySorted(runSvn("status"), "A child", "A child" + File.separatorChar + "a.txt");
    checkin();
    disableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile unversioned = createDirInCommand(myWorkingCopyDir, "unversioned");
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    verifySorted(runSvn("status"), "? unversioned");
    moveFileInCommand(child, unversioned);
    verifySorted(runSvn("status"), "? unversioned", "D child", "D child" + File.separator + "a.txt");
}

89. SvnRenameTest#testUndoMoveToUnversioned()

View license
@Test
public void testUndoMoveToUnversioned() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile file = createFileInCommand(myWorkingCopyDir, "a.txt", "A");
    final VirtualFile child = moveToNewPackage(file, "child");
    verifySorted(runSvn("status"), "A child", "A child" + File.separatorChar + "a.txt");
    checkin();
    disableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile unversioned = createDirInCommand(myWorkingCopyDir, "unversioned");
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    verifySorted(runSvn("status"), "? unversioned");
    moveFileInCommand(child, unversioned);
    verifySorted(runSvn("status"), "? unversioned", "D child", "D child" + File.separator + "a.txt");
    undo();
    verifySorted(runSvn("status"), "? unversioned");
}

90. SvnRenameTest#testUndoMoveToUnversionedCommitted()

View license
@Test
public void testUndoMoveToUnversionedCommitted() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile file = createFileInCommand(myWorkingCopyDir, "a.txt", "A");
    final VirtualFile child = moveToNewPackage(file, "child");
    verifySorted(runSvn("status"), "A child", "A child" + File.separatorChar + "a.txt");
    checkin();
    disableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile unversioned = createDirInCommand(myWorkingCopyDir, "unversioned");
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    verifySorted(runSvn("status"), "? unversioned");
    moveFileInCommand(child, unversioned);
    verifySorted(runSvn("status"), "? unversioned", "D child", "D child" + File.separator + "a.txt");
    checkin();
    undo();
    verifySorted(runSvn("status"), "? child", "? unversioned");
}

91. SvnRenameTest#testUndoNewMove()

View license
// IDEA-92941
@Test
public void testUndoNewMove() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile sink = createDirInCommand(myWorkingCopyDir, "sink");
    final VirtualFile child = createDirInCommand(myWorkingCopyDir, "child");
    verifySorted(runSvn("status"), "A child", "A sink");
    checkin();
    final VirtualFile file = createFileInCommand(child, "a.txt", "A");
    verifySorted(runSvn("status"), "A child" + File.separatorChar + "a.txt");
    moveFileInCommand(file, sink);
    verifySorted(runSvn("status"), "A sink" + File.separatorChar + "a.txt");
    undo();
    verifySorted(runSvn("status"), "A child" + File.separatorChar + "a.txt");
}

92. SvnRollbackTest#testRollbackAdd()

View license
@Test
public void testRollbackAdd() throws Exception {
    final SubTree tree = new SubTree(myWorkingCopyDir);
    checkin();
    final VirtualFile newDir = createDirInCommand(tree.mySourceDir, "newDir");
    final VirtualFile inNewDir = createFileInCommand(newDir, "f.txt", "12345");
    final VirtualFile inSource = createFileInCommand(tree.myTargetDir, "newF.txt", "54321");
    Assert.assertTrue(newDir != null && inNewDir != null && inSource != null);
    myDirtyScopeManager.markEverythingDirty();
    myChangeListManager.ensureUpToDate(false);
    final Change change = assertCreatedChange(newDir);
    final Change inNewDirChange = assertCreatedChange(inNewDir);
    final Change inSourceChange = assertCreatedChange(inSource);
    rollbackIMpl(Arrays.asList(change, inSourceChange), Collections.<Change>emptyList());
}

93. IgnoredFilesTest#testDirIsIgnored()

View license
@Test
public void testDirIsIgnored() throws Exception {
    //final String dirPath1 = myClientRoot.getPath() + "/a";
    final File dir = new File(myClientRoot, "a");
    dir.mkdir();
    final File innerDir = new File(dir, "innerDir");
    innerDir.mkdir();
    final File file1 = new File(innerDir, "file1");
    final File file2 = new File(innerDir, "file2");
    file1.createNewFile();
    file2.createNewFile();
    final VirtualFile innerVf = myLocalFileSystem.refreshAndFindFileByIoFile(innerDir);
    final VirtualFile vf1 = myLocalFileSystem.refreshAndFindFileByIoFile(file1);
    final VirtualFile vf2 = myLocalFileSystem.refreshAndFindFileByIoFile(file2);
    final IgnoredFileBean ignoredFileBean = IgnoredBeanFactory.ignoreUnderDirectory(FileUtil.toSystemIndependentName(dir.getPath()), myProject);
    myChangeListManager.addFilesToIgnore(ignoredFileBean);
    dirty();
    assertFoundAndIgnored(innerVf);
    assertFoundAndIgnored(vf1);
    assertFoundAndIgnored(vf2);
}

94. SvnCommittedViewTest#testAdd()

View license
@Test
public void testAdd() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);
    final VirtualFile d1 = createDirInCommand(myWorkingCopyDir, "d1");
    final VirtualFile f11 = createFileInCommand(d1, "f11.txt", "123\n456");
    final VirtualFile f12 = createFileInCommand(d1, "f12.txt", "----");
    // r1, addition without history
    checkin();
    final SvnVcs vcs = SvnVcs.getInstance(myProject);
    vcs.invokeRefreshSvnRoots();
    final CommittedChangesProvider<SvnChangeList, ChangeBrowserSettings> committedChangesProvider = vcs.getCommittedChangesProvider();
    final List<SvnChangeList> changeListList = committedChangesProvider.getCommittedChanges(committedChangesProvider.createDefaultSettings(), new SvnRepositoryLocation(myRepoUrl), 0);
    checkList(changeListList, 1, new Data[] { new Data(absPath(f11), FileStatus.ADDED, null), new Data(absPath(f12), FileStatus.ADDED, null), new Data(absPath(d1), FileStatus.ADDED, null) });
}

95. SvnRenameTest#testUndoMovePackage()

View license
// IDEADEV-19364
@Test
public void testUndoMovePackage() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile parent1 = createDirInCommand(myWorkingCopyDir, "parent1");
    final VirtualFile parent2 = createDirInCommand(myWorkingCopyDir, "parent2");
    final VirtualFile child = createDirInCommand(parent1, "child");
    createFileInCommand(child, "a.txt", "a");
    checkin();
    moveFileInCommand(child, parent2);
    undo();
    final File childPath = new File(parent1.getPath(), "child");
    Assert.assertTrue(childPath.exists());
    Assert.assertTrue(new File(childPath, "a.txt").exists());
}

96. SvnRenameTest#testMoveToUnversioned()

View license
@Test
public void testMoveToUnversioned() throws Exception {
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile file = createFileInCommand(myWorkingCopyDir, "a.txt", "A");
    final VirtualFile child = moveToNewPackage(file, "child");
    verifySorted(runSvn("status"), "A child", "A child" + File.separatorChar + "a.txt");
    checkin();
    disableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    final VirtualFile unversioned = createDirInCommand(myWorkingCopyDir, "unversioned");
    enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
    verifySorted(runSvn("status"), "? unversioned");
    moveFileInCommand(child, unversioned);
    verifySorted(runSvn("status"), "? unversioned", "D child", "D child" + File.separator + "a.txt");
}

97. SvnRollbackTest#testRollbackAdd()

View license
@Test
public void testRollbackAdd() throws Exception {
    final SubTree tree = new SubTree(myWorkingCopyDir);
    checkin();
    final VirtualFile newDir = createDirInCommand(tree.mySourceDir, "newDir");
    final VirtualFile inNewDir = createFileInCommand(newDir, "f.txt", "12345");
    final VirtualFile inSource = createFileInCommand(tree.myTargetDir, "newF.txt", "54321");
    Assert.assertTrue(newDir != null && inNewDir != null && inSource != null);
    myDirtyScopeManager.markEverythingDirty();
    myChangeListManager.ensureUpToDate(false);
    final Change change = assertCreatedChange(newDir);
    final Change inNewDirChange = assertCreatedChange(inNewDir);
    final Change inSourceChange = assertCreatedChange(inSource);
    rollbackIMpl(Arrays.asList(change, inSourceChange), Collections.<Change>emptyList());
}

98. UiDesignerExternalBuildTest#testCopyFormsRuntimeToArtifact()

View license
//IDEA-94779
public void testCopyFormsRuntimeToArtifact() throws IOException {
    VirtualFile file = createFile("src/A.java", "class A{}");
    VirtualFile srcRoot = file.getParent();
    Module module = addModule("a", srcRoot);
    Artifact a = addArtifact(root().module(module));
    make(a);
    assertOutput(a, fs().file("A.class"));
    File dir = PathManagerEx.findFileUnderCommunityHome("plugins/ui-designer/testData/build/copyFormsRuntimeToArtifact");
    FileUtil.copyDir(dir, VfsUtilCore.virtualToIoFile(srcRoot));
    srcRoot.refresh(false, false);
    make(a);
    File outputDir = VfsUtilCore.virtualToIoFile(getOutputDir(a));
    assertTrue(new File(outputDir, "A.class").exists());
    assertTrue(new File(outputDir, "B.class").exists());
    assertTrue(new File(outputDir, AbstractLayout.class.getName().replace('.', '/') + ".class").exists());
}

99. AddAssociationAction#addAssociation()

View license
protected void addAssociation(final PsiFile psiFile) {
    final VirtualFile virtualFile = psiFile.getVirtualFile();
    assert virtualFile != null;
    final FileChooserDescriptor descriptor = new AnyXMLDescriptor(true) {

        public boolean isFileSelectable(VirtualFile file) {
            return super.isFileSelectable(file) && !file.equals(virtualFile);
        }
    };
    final VirtualFile[] virtualFiles = FileChooser.chooseFiles(descriptor, psiFile.getProject(), psiFile.getVirtualFile());
    // cancel
    if (virtualFiles.length == 0)
        return;
    for (VirtualFile file : virtualFiles) {
        assert !virtualFile.equals(file);
        myManager.addAssociation(psiFile, file);
    }
}

100. PyConvertModuleToPackageAction#createPackageFromModule()

View license
@VisibleForTesting
public void createPackageFromModule(@NotNull final PyFile file) {
    final VirtualFile vFile = file.getVirtualFile();
    final VirtualFile parentDir = vFile.getParent();
    final String newPackageName = vFile.getNameWithoutExtension();
    final VirtualFile existing = parentDir.findChild(newPackageName);
    if (existing != null) {
        showFileExistsErrorMessage(existing, ID, file.getProject());
        return;
    }
    WriteCommandAction.runWriteCommandAction(file.getProject(), () -> {
        try {
            final VirtualFile packageDir = parentDir.createChildDirectory(PyConvertModuleToPackageAction.this, newPackageName);
            vFile.move(PyConvertModuleToPackageAction.this, packageDir);
            vFile.rename(PyConvertModuleToPackageAction.this, PyNames.INIT_DOT_PY);
        } catch (IOException e) {
            LOG.error(e);
        }
    });
}