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);
}
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();
}
}
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;
}
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;
}
}
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;
}
Aggregations