Search in sources :

Example 6 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project buck by facebook.

the class BuckGotoProvider method getGotoDeclarationTarget.

@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement source, Editor editor) {
    if (source != null && source.getLanguage() instanceof BuckLanguage) {
        // The parent type of the element must be BuckValue.
        BuckValue value = PsiTreeUtil.getParentOfType(source, BuckValue.class);
        if (value == null) {
            return null;
        }
        final Project project = editor.getProject();
        if (project == null) {
            return null;
        }
        String target = source.getText();
        if ((target.startsWith("'") && target.endsWith("'")) || (target.startsWith("\"") && target.endsWith("\""))) {
            target = target.substring(1, target.length() - 1);
        }
        VirtualFile targetFile = // Try to find the BUCK file
        Optional.fromNullable(BuckBuildUtil.getBuckFileFromAbsoluteTarget(project, target)).or(Optional.fromNullable(source.getContainingFile().getParent().getVirtualFile().findFileByRelativePath(target))).orNull();
        if (targetFile == null) {
            return null;
        }
        project.getMessageBus().syncPublisher(IntellijBuckAction.EVENT).consume(this.getClass().toString());
        return PsiManager.getInstance(project).findFile(targetFile);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BuckValue(com.facebook.buck.intellij.ideabuck.lang.psi.BuckValue) Project(com.intellij.openapi.project.Project) BuckLanguage(com.facebook.buck.intellij.ideabuck.lang.BuckLanguage)

Example 7 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project buck by facebook.

the class BuckToolWindowFactory method handleClickOnError.

private void handleClickOnError(BuckTreeNodeDetailError node) {
    TreeNode parentNode = node.getParent();
    if (parentNode instanceof BuckTreeNodeFileError) {
        BuckTreeNodeFileError buckParentNode = (BuckTreeNodeFileError) parentNode;
        DataContext dataContext = DataManager.getInstance().getDataContext();
        Project project = DataKeys.PROJECT.getData(dataContext);
        String relativePath = buckParentNode.getFilePath().replace(project.getBasePath(), "");
        VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
        OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile, node.getLine() - 1, node.getColumn() - 1);
        openFileDescriptor.navigate(true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) TreeNode(javax.swing.tree.TreeNode) BuckTreeNodeFileError(com.facebook.buck.intellij.ideabuck.ui.tree.BuckTreeNodeFileError) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 8 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project buck by facebook.

the class BuckCopyPasteProcessor method referenceNameToBuckFile.

private VirtualFile referenceNameToBuckFile(Project project, String reference) {
    // First test if it is a absolute path of a file.
    File tryFile = new File(reference);
    if (tryFile != null) {
        VirtualFile file = VfsUtil.findFileByIoFile(tryFile, true);
        if (file != null) {
            return BuckBuildUtil.getBuckFileFromDirectory(file.getParent());
        }
    }
    // Try class firstly.
    PsiClass classElement = JavaPsiFacade.getInstance(project).findClass(reference, GlobalSearchScope.allScope(project));
    if (classElement != null) {
        VirtualFile file = PsiUtilCore.getVirtualFile(classElement);
        return BuckBuildUtil.getBuckFileFromDirectory(file.getParent());
    }
    // Then try package.
    PsiPackage packageElement = JavaPsiFacade.getInstance(project).findPackage(reference);
    if (packageElement != null) {
        PsiDirectory directory = packageElement.getDirectories()[0];
        return BuckBuildUtil.getBuckFileFromDirectory(directory.getVirtualFile());
    }
    // Extract the package from the reference.
    int index = reference.lastIndexOf(".");
    if (index == -1) {
        return null;
    }
    reference = reference.substring(0, index);
    // Try to find the package again.
    packageElement = JavaPsiFacade.getInstance(project).findPackage(reference);
    if (packageElement != null) {
        PsiDirectory directory = packageElement.getDirectories()[0];
        return BuckBuildUtil.getBuckFileFromDirectory(directory.getVirtualFile());
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) BuckFile(com.facebook.buck.intellij.ideabuck.lang.BuckFile) File(java.io.File)

Example 9 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project qi4j-sdk by Qi4j.

the class AbstractIntention method isFileReadOnly.

protected static boolean isFileReadOnly(@NotNull Project project, @NotNull PsiFile file) {
    VirtualFile virtualFile = file.getVirtualFile();
    ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project);
    ReadonlyStatusHandler.OperationStatus operationStatus = readonlyStatusHandler.ensureFilesWritable(virtualFile);
    return operationStatus.hasReadonlyFiles();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ReadonlyStatusHandler(com.intellij.openapi.vfs.ReadonlyStatusHandler)

Example 10 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project android-selector-chapek by inmite.

the class SelectorChapekAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Log.d("---- Start - menu item clicked ----");
    VirtualFile selectedFile = DataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    if (isCorrectFolderSelected(selectedFile)) {
        new SelectorDetector(e.getProject()).detectAndCreateSelectors(selectedFile);
        showInfoDialog("Selectors were generated into 'drawable' folder", e);
    } else {
        if (selectedFile != null) {
            showErrorDialog("You need to select folder with image resources, for example 'drawables-xhdpi' " + "" + selectedFile.getName(), e);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)5443 File (java.io.File)757 Nullable (org.jetbrains.annotations.Nullable)719 Project (com.intellij.openapi.project.Project)718 NotNull (org.jetbrains.annotations.NotNull)703 PsiFile (com.intellij.psi.PsiFile)564 Module (com.intellij.openapi.module.Module)495 IOException (java.io.IOException)327 ArrayList (java.util.ArrayList)258 Document (com.intellij.openapi.editor.Document)241 PsiElement (com.intellij.psi.PsiElement)205 Test (org.junit.Test)193 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)124 PsiDirectory (com.intellij.psi.PsiDirectory)124 XmlFile (com.intellij.psi.xml.XmlFile)124 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)116 Editor (com.intellij.openapi.editor.Editor)114 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)100 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)91 List (java.util.List)90