Search in sources :

Example 36 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by JetBrains.

the class DartAnalysisServerService method doConfigureImportedLibraries.

private static void doConfigureImportedLibraries(@NotNull final Project project, @NotNull final Collection<String> filePaths) {
    final DartSdk sdk = DartSdk.getDartSdk(project);
    if (sdk == null)
        return;
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final SortedSet<String> folderPaths = new TreeSet<>();
    final Collection<String> rootsToAddToLib = new THashSet<>();
    for (final String path : filePaths) {
        if (path != null) {
            folderPaths.add(PathUtil.getParentPath(FileUtil.toSystemIndependentName(path)));
        }
    }
    outer: for (final String path : folderPaths) {
        final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(path);
        if (!path.startsWith(sdk.getHomePath() + "/") && (vFile == null || !fileIndex.isInContent(vFile))) {
            for (String configuredPath : rootsToAddToLib) {
                if (path.startsWith(configuredPath + "/")) {
                    // folderPaths is sorted so subfolders go after parent folder
                    continue outer;
                }
            }
            rootsToAddToLib.add(path);
        }
    }
    final Processor<? super PsiFileSystemItem> falseProcessor = (Processor<PsiFileSystemItem>) item -> false;
    final Condition<Module> moduleFilter = module -> DartSdkLibUtil.isDartSdkEnabled(module) && !FilenameIndex.processFilesByName(PubspecYamlUtil.PUBSPEC_YAML, false, falseProcessor, module.getModuleContentScope(), project, null);
    final DartFileListener.DartLibInfo libInfo = new DartFileListener.DartLibInfo(true);
    libInfo.addRoots(rootsToAddToLib);
    final Library library = DartFileListener.updatePackagesLibraryRoots(project, libInfo);
    DartFileListener.updateDependenciesOnDartPackagesLibrary(project, moduleFilter, library);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartFileType(com.jetbrains.lang.dart.DartFileType) UIUtil(com.intellij.util.ui.UIUtil) HtmlUtil(com.intellij.xml.util.HtmlUtil) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) Logging(com.google.dart.server.utilities.logging.Logging) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) THashMap(gnu.trove.THashMap) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) Library(com.intellij.openapi.roots.libraries.Library) Task(com.intellij.openapi.progress.Task) DartProblemsView(com.jetbrains.lang.dart.ide.errorTreeView.DartProblemsView) ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) org.dartlang.analysis.server.protocol(org.dartlang.analysis.server.protocol) DebugPrintStream(com.google.dart.server.internal.remote.DebugPrintStream) DartSdkUpdateChecker(com.jetbrains.lang.dart.sdk.DartSdkUpdateChecker) RemoteAnalysisServerImpl(com.google.dart.server.internal.remote.RemoteAnalysisServerImpl) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) QueueProcessor(com.intellij.util.concurrency.QueueProcessor) DartYamlFileTypeFactory(com.jetbrains.lang.dart.DartYamlFileTypeFactory) AnalysisServer(com.google.dart.server.generated.AnalysisServer) DartSdkUtil(com.jetbrains.lang.dart.sdk.DartSdkUtil) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) DartBundle(com.jetbrains.lang.dart.DartBundle) Nullable(org.jetbrains.annotations.Nullable) CountDownLatch(java.util.concurrent.CountDownLatch) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Contract(org.jetbrains.annotations.Contract) ServiceManager(com.intellij.openapi.components.ServiceManager) DartPubActionBase(com.jetbrains.lang.dart.ide.actions.DartPubActionBase) EditorFactory(com.intellij.openapi.editor.EditorFactory) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Consumer(com.intellij.util.Consumer) DartFileListener(com.jetbrains.lang.dart.DartFileListener) com.google.dart.server(com.google.dart.server) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) java.util(java.util) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FilenameIndex(com.intellij.psi.search.FilenameIndex) StdioServerSocket(com.google.dart.server.internal.remote.StdioServerSocket) SearchScope(com.intellij.psi.search.SearchScope) ContainerUtil(com.intellij.util.containers.ContainerUtil) DartQuickAssistIntention(com.jetbrains.lang.dart.assists.DartQuickAssistIntention) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Lists(com.google.common.collect.Lists) Comparing(com.intellij.openapi.util.Comparing) EvictingQueue(com.google.common.collect.EvictingQueue) IntentionManager(com.intellij.codeInsight.intention.IntentionManager) Project(com.intellij.openapi.project.Project) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) DartSdkLibUtil(com.jetbrains.lang.dart.sdk.DartSdkLibUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Disposable(com.intellij.openapi.Disposable) File(java.io.File) DartFeedbackBuilder(com.jetbrains.lang.dart.ide.errorTreeView.DartFeedbackBuilder) TimeUnit(java.util.concurrent.TimeUnit) PubspecYamlUtil(com.jetbrains.lang.dart.util.PubspecYamlUtil) QuickAssistSet(com.jetbrains.lang.dart.assists.QuickAssistSet) Condition(com.intellij.openapi.util.Condition) QueueProcessor(com.intellij.util.concurrency.QueueProcessor) THashSet(gnu.trove.THashSet) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) DartFileListener(com.jetbrains.lang.dart.DartFileListener) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module)

Example 37 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by JetBrains.

the class JSFlexFileReference method bindToElement.

// - absolute paths remain absolute (i.e. not relative to project root)
// - relative paths are kept relative to what they were relative to before refactoring
@Override
public PsiElement bindToElement(@NotNull final PsiElement element) throws IncorrectOperationException {
    if (!(element instanceof PsiFileSystemItem)) {
        throw new IncorrectOperationException("Cannot bind to element, should be instanceof PsiFileSystemItem: " + element);
    }
    final PsiFileSystemItem fileSystemItem = (PsiFileSystemItem) element;
    final VirtualFile destVFile = fileSystemItem.getVirtualFile();
    if (destVFile == null)
        throw new IncorrectOperationException("Cannot bind to non-physical element:" + element);
    PsiFile currentPsiFile = getElement().getContainingFile();
    final PsiElement contextPsiFile = currentPsiFile.getContext();
    if (contextPsiFile != null)
        currentPsiFile = contextPsiFile.getContainingFile();
    final VirtualFile currentVFile = currentPsiFile.getVirtualFile();
    if (currentVFile == null)
        throw new IncorrectOperationException("Cannot bind from non-physical element:" + currentPsiFile);
    final Project project = element.getProject();
    String newName = null;
    switch(myRelativeToWhat) {
        case Absolute:
            newName = destVFile.getPath();
            break;
        case CurrentFile:
            newName = getRelativePath(currentVFile, destVFile, '/');
            break;
        case ProjectRoot:
            final VirtualFile projectRoot = project.getBaseDir();
            newName = projectRoot == null ? null : getRelativePath(projectRoot, destVFile, '/');
            break;
        case SourceRoot:
            // first try to get source root that contains the file
            final VirtualFile sourceRootForFile = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(destVFile);
            if (sourceRootForFile != null) {
                newName = getRelativePath(sourceRootForFile, destVFile, '/');
            } else {
                final Module module = ModuleUtilCore.findModuleForFile(currentVFile, project);
                if (module != null) {
                    final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots();
                    for (final VirtualFile sourceRoot : sourceRoots) {
                        final String relativePath = getRelativePath(sourceRoot, destVFile, '/');
                        if (relativePath != null) {
                            newName = relativePath;
                            break;
                        }
                    }
                }
            }
            break;
        case Other:
            break;
    }
    if (newName != null && getFileReferenceSet().getPathString().startsWith("/") && !newName.startsWith("/")) {
        newName = "/" + newName;
    }
    return newName == null ? element : rename(newName);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiFile(com.intellij.psi.PsiFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 38 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by JetBrains.

the class InjectedPsiVisitor method processResourceDirective.

private ValueWriter processResourceDirective(JSAttribute attribute) {
    String key = null;
    PropertiesFile bundle = null;
    for (JSAttributeNameValuePair p : attribute.getValues()) {
        final String name = p.getName();
        if ("key".equals(name)) {
            key = p.getSimpleValue();
        } else if ("bundle".equals(name)) {
            try {
                // IDEA-74868
                final PsiFileSystemItem referencedPsiFile = InjectionUtil.getReferencedPsiFile(p);
                if (referencedPsiFile instanceof PropertiesFile) {
                    bundle = (PropertiesFile) referencedPsiFile;
                } else {
                    LOG.warn("skip resource directive, referenced file is not properties file " + host.getText());
                }
            } catch (InvalidPropertyException e) {
                invalidPropertyException = e;
                return InjectedASWriter.IGNORE;
            }
        }
    }
    if (key == null || key.isEmpty() || bundle == null) {
        LOG.warn("skip resource directive, one of the required attributes is missed " + host.getText());
        return InjectedASWriter.IGNORE;
    }
    final IProperty property = bundle.findPropertyByKey(key);
    if (property == null) {
        LOG.warn("skip resource directive, key not found " + host.getText());
        return InjectedASWriter.IGNORE;
    }
    return new ResourceDirectiveValueWriter(property.getUnescapedValue());
}
Also used : IProperty(com.intellij.lang.properties.IProperty) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Example 39 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.

the class AntDomTargetReference method doResolve.

@Nullable
private TargetResolver.Result doResolve(@Nullable final String referenceText) {
    final AntDomElement hostingElement = getHostingAntDomElement();
    if (hostingElement == null) {
        return null;
    }
    AntDomProject projectToSearchFrom;
    AntDomTarget contextTarget;
    if (hostingElement instanceof AntDomAnt) {
        final PsiFileSystemItem antFile = ((AntDomAnt) hostingElement).getAntFilePath().getValue();
        projectToSearchFrom = antFile instanceof PsiFile ? AntSupport.getAntDomProjectForceAntFile((PsiFile) antFile) : null;
        contextTarget = null;
    } else {
        projectToSearchFrom = hostingElement.getContextAntProject();
        contextTarget = hostingElement.getParentOfType(AntDomTarget.class, false);
    }
    if (projectToSearchFrom == null) {
        return null;
    }
    return TargetResolver.resolve(projectToSearchFrom, contextTarget, referenceText == null ? Collections.<String>emptyList() : Collections.singletonList(referenceText));
}
Also used : PsiFile(com.intellij.psi.PsiFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Nullable(org.jetbrains.annotations.Nullable)

Example 40 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.

the class AntDomDirname method calcPropertyValue.

@Nullable
protected final String calcPropertyValue(String propertyName) {
    final PsiFileSystemItem fsItem = getFile().getValue();
    if (fsItem != null) {
        final PsiFileSystemItem parent = fsItem.getParent();
        if (parent != null) {
            final VirtualFile vFile = parent.getVirtualFile();
            if (vFile != null) {
                return FileUtil.toSystemDependentName(vFile.getPath());
            }
        }
    }
    // according to the doc, defaulting to project's current dir
    final String projectBasedirPath = getContextAntProject().getProjectBasedirPath();
    if (projectBasedirPath == null) {
        return null;
    }
    return FileUtil.toSystemDependentName(projectBasedirPath);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)60 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 Nullable (org.jetbrains.annotations.Nullable)20 PsiElement (com.intellij.psi.PsiElement)18 PsiFile (com.intellij.psi.PsiFile)18 Project (com.intellij.openapi.project.Project)14 PsiDirectory (com.intellij.psi.PsiDirectory)14 NotNull (org.jetbrains.annotations.NotNull)8 Module (com.intellij.openapi.module.Module)7 File (java.io.File)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 ArrayList (java.util.ArrayList)5 PsiManager (com.intellij.psi.PsiManager)4 IProperty (com.intellij.lang.properties.IProperty)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 SearchScope (com.intellij.psi.search.SearchScope)2 QualifiedName (com.intellij.psi.util.QualifiedName)2 XmlFile (com.intellij.psi.xml.XmlFile)2