Search in sources :

Example 11 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow in project intellij-plugins by JetBrains.

the class ExpressionBinding method writeFunction.

private static void writeFunction(JSFunction function, BaseWriter writer, @Nullable ValueReferenceResolver valueReferenceResolver, boolean isBinding) throws InvalidPropertyException {
    final PsiFile psiFile = function.getContainingFile();
    if (psiFile instanceof JSFile) {
        VirtualFile file = psiFile.getViewProvider().getVirtualFile();
        if (file instanceof VirtualFileWindow) {
            if (ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex().isInSourceContent(((VirtualFileWindow) file).getDelegate())) {
                throw new UnsupportedOperationException(function.getText());
            }
        }
    }
    writeFunction(function, writer, valueReferenceResolver, isBinding, null, null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) PsiFile(com.intellij.psi.PsiFile)

Example 12 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow in project intellij-plugins by JetBrains.

the class AddImportECMAScriptClassOrFunctionAction method getCandidates.

public static Collection<JSQualifiedNamedElement> getCandidates(final Editor editor, final PsiFile file, final String name) {
    final Module module = ModuleUtil.findModuleForPsiElement(file);
    if (module != null) {
        GlobalSearchScope searchScope;
        VirtualFile virtualFile = file.getVirtualFile();
        if (virtualFile instanceof VirtualFileWindow)
            virtualFile = ((VirtualFileWindow) virtualFile).getDelegate();
        if (GlobalSearchScopes.projectProductionScope(file.getProject()).contains(virtualFile)) {
            // skip tests suggestions
            searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
        } else {
            searchScope = JSResolveUtil.getResolveScope(file);
        }
        return JSResolveUtil.findElementsByName(name, editor.getProject(), searchScope);
    } else {
        return Collections.emptyList();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) Module(com.intellij.openapi.module.Module)

Example 13 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow in project intellij-plugins by JetBrains.

the class ActionScriptResolveScopeProvider method getResolveScope.

@Nullable
private GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project, boolean checkApplicable) {
    if (file instanceof VirtualFileWindow) {
        file = ((VirtualFileWindow) file).getDelegate();
    }
    if (checkApplicable && !isApplicable(file))
        return null;
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final Module module = projectFileIndex.getModuleForFile(file);
    if (module != null) {
        boolean includeTests = projectFileIndex.isInTestSourceContent(file) || !projectFileIndex.isInSourceContent(file);
        final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, includeTests);
        // TODO [Konstantin.Ulitin] add package and swc file types
        //final GlobalSearchScope fileTypesScope =
        //  GlobalSearchScope.getScopeRestrictedByFileTypes(moduleScope, ActionScriptFileType.INSTANCE,
        //                                                  FlexApplicationComponent.SWF_FILE_TYPE, FlexApplicationComponent.MXML);
        final GlobalSearchScope fileTypesScope = moduleScope.intersectWith(GlobalSearchScope.notScope(GlobalSearchScope.getScopeRestrictedByFileTypes(moduleScope, TypeScriptFileType.INSTANCE, JavaScriptFileType.INSTANCE)));
        return fileTypesScope.union(GlobalSearchScope.filesScope(project, JSCorePredefinedLibrariesProvider.getActionScriptPredefinedLibraryFiles()));
    }
    return null;
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.

the class PerFileMappingsBase method getMappingInner.

@Nullable
protected T getMappingInner(@Nullable VirtualFile file, @Nullable Map<VirtualFile, T> mappings, @Nullable Key<T> pusherKey) {
    if (file instanceof VirtualFileWindow) {
        final VirtualFileWindow window = (VirtualFileWindow) file;
        file = window.getDelegate();
    }
    VirtualFile originalFile = file instanceof LightVirtualFile ? ((LightVirtualFile) file).getOriginalFile() : null;
    if (Comparing.equal(originalFile, file))
        originalFile = null;
    if (file != null) {
        final T pushedValue = pusherKey == null ? null : file.getUserData(pusherKey);
        if (pushedValue != null)
            return pushedValue;
    }
    if (originalFile != null) {
        final T pushedValue = pusherKey == null ? null : originalFile.getUserData(pusherKey);
        if (pushedValue != null)
            return pushedValue;
    }
    if (mappings == null)
        return null;
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (mappings) {
        T t = getMappingForHierarchy(file, mappings);
        if (t != null)
            return t;
        t = getMappingForHierarchy(originalFile, mappings);
        if (t != null)
            return t;
        Project project = getProject();
        if (project == null || file == null || file.getFileSystem() instanceof NonPhysicalFileSystem || ProjectFileIndex.getInstance(project).isInContent(file)) {
            return mappings.get(null);
        }
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Project(com.intellij.openapi.project.Project) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) NonPhysicalFileSystem(com.intellij.openapi.vfs.NonPhysicalFileSystem) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with VirtualFileWindow

use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.

the class AbstractProjectViewPane method getSelectedDirectories.

@NotNull
public PsiDirectory[] getSelectedDirectories() {
    List<PsiDirectory> directories = ContainerUtil.newArrayList();
    for (PsiDirectoryNode node : getSelectedNodes(PsiDirectoryNode.class)) {
        PsiDirectory directory = node.getValue();
        if (directory != null) {
            directories.add(directory);
            Object parentValue = node.getParent().getValue();
            if (parentValue instanceof PsiDirectory && Registry.is("projectView.choose.directory.on.compacted.middle.packages")) {
                while (true) {
                    directory = directory.getParentDirectory();
                    if (directory == null || directory.equals(parentValue)) {
                        break;
                    }
                    directories.add(directory);
                }
            }
        }
    }
    if (!directories.isEmpty()) {
        return directories.toArray(new PsiDirectory[directories.size()]);
    }
    final PsiElement[] elements = getSelectedPSIElements();
    if (elements.length == 1) {
        final PsiElement element = elements[0];
        if (element instanceof PsiDirectory) {
            return new PsiDirectory[] { (PsiDirectory) element };
        } else if (element instanceof PsiDirectoryContainer) {
            return ((PsiDirectoryContainer) element).getDirectories();
        } else {
            final PsiFile containingFile = element.getContainingFile();
            if (containingFile != null) {
                final PsiDirectory psiDirectory = containingFile.getContainingDirectory();
                if (psiDirectory != null) {
                    return new PsiDirectory[] { psiDirectory };
                }
                final VirtualFile file = containingFile.getVirtualFile();
                if (file instanceof VirtualFileWindow) {
                    final VirtualFile delegate = ((VirtualFileWindow) file).getDelegate();
                    final PsiFile delegatePsiFile = containingFile.getManager().findFile(delegate);
                    if (delegatePsiFile != null && delegatePsiFile.getContainingDirectory() != null) {
                        return new PsiDirectory[] { delegatePsiFile.getContainingDirectory() };
                    }
                }
                return PsiDirectory.EMPTY_ARRAY;
            }
        }
    } else {
        final DefaultMutableTreeNode selectedNode = getSelectedNode();
        if (selectedNode != null) {
            return getSelectedDirectoriesInAmbiguousCase(selectedNode);
        }
    }
    return PsiDirectory.EMPTY_ARRAY;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Nullable (org.jetbrains.annotations.Nullable)7 NotNull (org.jetbrains.annotations.NotNull)5 DocumentWindow (com.intellij.injected.editor.DocumentWindow)4 Project (com.intellij.openapi.project.Project)4 Document (com.intellij.openapi.editor.Document)3 Module (com.intellij.openapi.module.Module)3 TextRange (com.intellij.openapi.util.TextRange)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 Language (com.intellij.lang.Language)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 SmartList (com.intellij.util.SmartList)2 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)1 ASTNode (com.intellij.lang.ASTNode)1 Editor (com.intellij.openapi.editor.Editor)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 Pair (com.intellij.openapi.util.Pair)1