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