use of com.intellij.psi.PsiManager in project checkstyle-idea by jshiell.
the class ScanFiles method findAllFilesFor.
private List<PsiFile> findAllFilesFor(@NotNull final List<VirtualFile> virtualFiles) {
final List<PsiFile> childFiles = new ArrayList<>();
final PsiManager psiManager = PsiManager.getInstance(this.plugin.getProject());
for (final VirtualFile virtualFile : virtualFiles) {
childFiles.addAll(buildFilesList(psiManager, virtualFile));
}
return childFiles;
}
use of com.intellij.psi.PsiManager in project yii2support by nvlad.
the class CompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
final PsiElement psiElement = completionParameters.getPosition();
final MethodReference method = PsiTreeUtil.getParentOfType(psiElement, MethodReference.class);
if (method == null || method.getParameters().length == 0) {
return;
}
if (!ViewUtil.isValidRenderMethod(method)) {
return;
}
PsiElement viewParameter = psiElement;
while (viewParameter != null && !(viewParameter.getParent() instanceof ParameterList)) {
viewParameter = viewParameter.getParent();
}
if (viewParameter == null || !viewParameter.equals(method.getParameters()[0])) {
return;
}
final ViewResolve resolve = ViewUtil.resolveView(viewParameter);
if (resolve == null) {
return;
}
final Project project = psiElement.getProject();
final GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
int prefixLength = resolve.key.length();
int lastSlashPosition = resolve.key.lastIndexOf('/');
if (lastSlashPosition != -1 && !resolve.key.endsWith("/")) {
prefixLength = lastSlashPosition + 1;
}
if (!completionParameters.isAutoPopup()) {
if (completionResultSet.getPrefixMatcher().getPrefix().startsWith("@") && lastSlashPosition == -1) {
final String prefix = completionResultSet.getPrefixMatcher().getPrefix();
completionResultSet = completionResultSet.withPrefixMatcher(prefix.substring(1));
prefixLength = 1;
} else {
completionResultSet = completionResultSet.withPrefixMatcher(resolve.key.substring(prefixLength));
}
}
if (completionResultSet.getPrefixMatcher().getPrefix().equals("@")) {
completionResultSet = completionResultSet.withPrefixMatcher("");
}
final String prefixFilter = resolve.key.substring(0, prefixLength);
final Set<String> keys = new HashSet<>();
fileBasedIndex.processAllKeys(ViewFileIndex.identity, key -> {
if (key.startsWith(prefixFilter)) {
keys.add(key);
}
return true;
}, scope, null);
final PsiManager psiManager = PsiManager.getInstance(project);
boolean localViewSearch = false;
if (resolve.from == ViewResolveFrom.View) {
final String value = PhpUtil.getValue(viewParameter);
localViewSearch = !value.startsWith("@") && !value.startsWith("//");
}
final String defaultViewExtension = '.' + Yii2SupportSettings.getInstance(psiElement.getProject()).defaultViewExtension;
for (String key : keys) {
Collection<ViewInfo> views = fileBasedIndex.getValues(ViewFileIndex.identity, key, scope);
for (ViewInfo view : views) {
if (!resolve.application.equals(view.application)) {
continue;
}
if (localViewSearch && !resolve.theme.equals(view.theme)) {
continue;
}
PsiFile psiFile = psiManager.findFile(view.getVirtualFile());
if (psiFile != null) {
String insertText = key.substring(prefixLength);
if (insertText.endsWith(defaultViewExtension)) {
insertText = insertText.substring(0, insertText.length() - defaultViewExtension.length());
}
completionResultSet.addElement(new ViewLookupElement(psiFile, insertText));
break;
} else {
System.out.println(view.fileUrl + " => not exists");
}
}
}
}
use of com.intellij.psi.PsiManager in project Perl5-IDEA by Camelcade.
the class PodFileUtil method processPodFilesByDescriptor.
public static void processPodFilesByDescriptor(Project project, PodLinkDescriptor descriptor, Processor<PsiFile> processor) {
if (descriptor.getFileId() != null) {
// seek file
String fileId = descriptor.getFileId();
if (// can be Foo/Bar.pod or Foo/Bar.pm
fileId.contains(PerlPackageUtil.PACKAGE_SEPARATOR) || !StringUtil.startsWith(fileId, "perl")) {
final PsiManager psiManager = PsiManager.getInstance(project);
String podRelativePath = PodFileUtil.getFilenameFromPackage(fileId);
String packageRelativePath = PerlPackageUtil.getPackagePathByName(fileId);
for (VirtualFile classRoot : PerlProjectManager.getInstance(project).getAllLibraryRoots()) {
VirtualFile targetVirtualFile = classRoot.findFileByRelativePath(podRelativePath);
if (targetVirtualFile != null) {
if (!processor.process(psiManager.findFile(targetVirtualFile))) {
return;
}
}
targetVirtualFile = classRoot.findFileByRelativePath(packageRelativePath);
if (targetVirtualFile != null) {
if (!processor.process(psiManager.findFile(targetVirtualFile))) {
return;
}
}
}
} else // top level file perl.*
{
fileId += "." + PodFileType.EXTENSION;
for (PsiFile podFile : FilenameIndex.getFilesByName(project, fileId, GlobalSearchScope.allScope(project))) {
if (!processor.process(podFile)) {
return;
}
}
}
}
}
use of com.intellij.psi.PsiManager in project Perl5-IDEA by Camelcade.
the class TemplateToolkitFileReferenceHelper method getRoots.
@NotNull
@Override
public Collection<PsiFileSystemItem> getRoots(@NotNull Module module) {
Collection<PsiFileSystemItem> result = new ArrayList<>();
PsiManager psiManager = PsiManager.getInstance(module.getProject());
for (VirtualFile root : ManagingFS.getInstance().getLocalRoots()) {
PsiDirectory directory = psiManager.findDirectory(root);
if (directory != null) {
result.add(directory);
}
}
return result;
}
use of com.intellij.psi.PsiManager in project sonarlint-intellij by SonarSource.
the class SonarClearIssuesAction method findFiles.
public Collection<PsiFile> findFiles(Project project, VirtualFile[] files) {
PsiManager psiManager = PsiManager.getInstance(project);
List<PsiFile> psiFiles = new ArrayList<>(files.length);
for (VirtualFile vFile : files) {
if (!vFile.isValid()) {
continue;
}
PsiFile psiFile = psiManager.findFile(vFile);
if (psiFile != null) {
psiFiles.add(psiFile);
} else {
LOGGER.warn("Couldn't find PSI for file: " + vFile.getPath());
}
}
return psiFiles;
}
Aggregations