Search in sources :

Example 6 with VFile

use of jetbrains.communicator.core.vfs.VFile in project intellij-plugins by JetBrains.

the class ProjectsDataFiller method fillProjectData.

private void fillProjectData(Project openProject, final ProjectsData result) {
    VirtualFile[] openFiles = FileEditorManager.getInstance(openProject).getOpenFiles();
    List<VFile> fileInfos = new ArrayList<>(openFiles.length);
    for (VirtualFile openFile : openFiles) {
        VFile vFile = VFSUtil.createFileFrom(openFile, openProject);
        if (vFile != null) {
            if (vFile.getProjectName() != null) {
                fileInfos.add(vFile);
            } else {
                result.addNonProjectFile(vFile);
            }
        }
    }
    result.setProjectFiles(openProject.getName(), fileInfos.toArray(new VFile[fileInfos.size()]));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) VFile(jetbrains.communicator.core.vfs.VFile)

Example 7 with VFile

use of jetbrains.communicator.core.vfs.VFile in project intellij-plugins by JetBrains.

the class VFSUtil method _createFileFrom.

private static VFile _createFileFrom(Project project, VirtualFile file) {
    VFile result = null;
    Document document = FileDocumentManager.getInstance().getDocument(file);
    Project[] openProjects = getOpenProjects();
    for (int i = 0; i < openProjects.length && result == null; i++) {
        Project openProject = openProjects[i];
        if (!openProject.isInitialized() && !ApplicationManager.getApplication().isUnitTestMode())
            continue;
        if (document != null) {
            PsiFile psiFile = PsiDocumentManager.getInstance(openProject).getPsiFile(document);
            if (isJavaFile(psiFile)) {
                PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile;
                assert psiJavaFile != null;
                final PsiClass[] classes = psiJavaFile.getClasses();
                if (classes.length > 0) {
                    result = createResultIfNeeded(result, file);
                    result.setFQName(classes[0].getQualifiedName());
                }
            }
        }
        ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(openProject).getFileIndex();
        if (projectFileIndex.isInSource(file)) {
            VirtualFile sourceRoot = projectFileIndex.getSourceRootForFile(file);
            result = createResultIfNeeded(result, file);
            result.setSourcePath(getRelativePath(file, sourceRoot));
        }
        if (projectFileIndex.isInContent(file)) {
            VirtualFile contentRoot = projectFileIndex.getContentRootForFile(file);
            result = createResultIfNeeded(result, file);
            result.setContentPath(getRelativePath(file, contentRoot));
        }
    }
    if (result == null) {
        result = VFile.create(file.getPath(), null, file.isWritable());
    }
    if (project != null) {
        result.setProjectName(project.getName());
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Document(com.intellij.openapi.editor.Document) VFile(jetbrains.communicator.core.vfs.VFile)

Example 8 with VFile

use of jetbrains.communicator.core.vfs.VFile in project intellij-plugins by JetBrains.

the class CodePointerXmlMessageTest method testComplexVFile.

public void testComplexVFile() throws Throwable {
    VFile expected = VFile.create("foo/bar", "bar", false);
    expected.setContents("#$@#@#$что-то такое");
    expected.setProjectName("project");
    expected.setFQName("some FQName");
    expected.setSourcePath("some source path");
    _test("", expected, new CodePointer(1, 2, 3, 4));
}
Also used : CodePointer(jetbrains.communicator.core.vfs.CodePointer) VFile(jetbrains.communicator.core.vfs.VFile)

Example 9 with VFile

use of jetbrains.communicator.core.vfs.VFile in project intellij-plugins by JetBrains.

the class ProjectsDataTest method testProjectNameInFileInfo.

public void testProjectNameInFileInfo() throws Exception {
    VFile fileInfo = VFile.create("Path");
    myProjectsData.setProjectFiles(VFile.PROJECT_NAME_ATTR, new VFile[] { fileInfo });
    assertEquals(VFile.PROJECT_NAME_ATTR, fileInfo.getProjectName());
    VFile fileInfo1 = VFile.create("Path");
    myProjectsData.addNonProjectFile(fileInfo1);
    assertNull(fileInfo1.getProjectName(), fileInfo1.getProjectName());
    VFile vFile = myProjectsData.getProjectFiles(VFile.PROJECT_NAME_ATTR)[0];
    assertEquals("Should be equal", fileInfo, vFile);
    assertEquals("Project name shoud be kept", VFile.PROJECT_NAME_ATTR, vFile.getProjectName());
    VFile vFile1 = myProjectsData.getNonProjectFiles()[0];
    assertEquals("Should be equal", fileInfo1, vFile1);
    assertNull("Project name shoud be kept", vFile1.getProjectName());
}
Also used : VFile(jetbrains.communicator.core.vfs.VFile)

Example 10 with VFile

use of jetbrains.communicator.core.vfs.VFile in project intellij-plugins by JetBrains.

the class IncomingCodePointerMessage method createPositionCorrector.

private PositionCorrector createPositionCorrector() {
    updateFacade();
    VFile localFile = (VFile) myRemoteFile.clone();
    myFacade.fillFileContents(localFile);
    return new PositionCorrector(myFacade, myRemoteFile.getContents(), localFile.getContents());
}
Also used : PositionCorrector(jetbrains.communicator.util.PositionCorrector) VFile(jetbrains.communicator.core.vfs.VFile)

Aggregations

VFile (jetbrains.communicator.core.vfs.VFile)24 CodePointer (jetbrains.communicator.core.vfs.CodePointer)6 MockUser (jetbrains.communicator.mock.MockUser)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 EventBroadcaster (jetbrains.communicator.core.EventBroadcaster)2 IDEFacade (jetbrains.communicator.ide.IDEFacade)2 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 Project (com.intellij.openapi.project.Project)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 SendCodePointerCommand (jetbrains.communicator.commands.SendCodePointerCommand)1 ShowDiffCommand (jetbrains.communicator.commands.ShowDiffCommand)1 EventVisitor (jetbrains.communicator.core.EventVisitor)1 IDEtalkAdapter (jetbrains.communicator.core.IDEtalkAdapter)1 IDEtalkEvent (jetbrains.communicator.core.IDEtalkEvent)1 CodePointerEvent (jetbrains.communicator.core.transport.CodePointerEvent)1