use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class InsertComponentProcessor method checkAddDependencyOnInsert.
private boolean checkAddDependencyOnInsert(final ComponentItem item) {
if (item.getClassName().equals(HSpacer.class.getName()) || item.getClassName().equals(VSpacer.class.getName())) {
// this is mostly required for IDEA developers, so that developers don't receive prompt to offer ui-designer-impl dependency
return true;
}
PsiManager manager = PsiManager.getInstance(myEditor.getProject());
final GlobalSearchScope projectScope = GlobalSearchScope.allScope(myEditor.getProject());
final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myEditor.getModule());
final PsiClass componentClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(item.getClassName(), projectScope);
if (componentClass != null && JavaPsiFacade.getInstance(manager.getProject()).findClass(item.getClassName(), moduleScope) == null) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myEditor.getProject()).getFileIndex();
List<OrderEntry> entries = fileIndex.getOrderEntriesForFile(componentClass.getContainingFile().getVirtualFile());
if (entries.size() > 0) {
if (entries.get(0) instanceof ModuleSourceOrderEntry) {
if (!checkAddModuleDependency(item, (ModuleSourceOrderEntry) entries.get(0)))
return false;
} else if (entries.get(0) instanceof LibraryOrderEntry) {
if (!checkAddLibraryDependency(item, (LibraryOrderEntry) entries.get(0)))
return false;
}
}
}
return true;
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class Java15FormInspection method checkComponentProperties.
protected void checkComponentProperties(Module module, final IComponent component, final FormErrorCollector collector) {
final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
final PsiManager psiManager = PsiManager.getInstance(module.getProject());
final PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(component.getComponentClassName(), scope);
if (aClass == null) {
return;
}
for (final IProperty prop : component.getModifiedProperties()) {
final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, prop.getName(), false, true);
if (getter == null)
continue;
final LanguageLevel languageLevel = LanguageLevelUtil.getEffectiveLanguageLevel(module);
if (Java15APIUsageInspection.getLastIncompatibleLanguageLevel(getter, languageLevel) != null) {
registerError(component, collector, prop, "@since " + Java15APIUsageInspection.getShortName(languageLevel));
}
}
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class CompilerHierarchyInfoImpl method getHierarchyChildren.
@Override
@NotNull
public Stream<PsiElement> getHierarchyChildren() {
PsiManager psiManager = PsiManager.getInstance(myProject);
final LanguageLightRefAdapter adapter = ObjectUtils.notNull(CompilerReferenceServiceImpl.findAdapterForFileType(mySearchFileType));
return myCandidatePerFile.entrySet().stream().filter(e -> mySearchScope.contains(e.getKey())).flatMap(e -> {
final VirtualFile file = e.getKey();
final Object[] definitions = e.getValue();
final PsiElement[] hierarchyChildren = ReadAction.compute(() -> {
final PsiFileWithStubSupport psiFile = (PsiFileWithStubSupport) psiManager.findFile(file);
return mySearchType.performSearchInFile(definitions, myBaseClass, psiFile, adapter);
});
if (hierarchyChildren.length == definitions.length) {
return Stream.of(hierarchyChildren);
} else {
LOG.assertTrue(mySearchType == CompilerHierarchySearchType.DIRECT_INHERITOR, "Should not happens for functional expression search");
return Stream.of(hierarchyChildren).filter(c -> ReadAction.compute(() -> adapter.isDirectInheritor(c, myBaseClass)));
}
});
}
use of com.intellij.psi.PsiManager in project kotlin by JetBrains.
the class BasicTest method createJetFileList.
private static List<KtFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
List<KtFile> libFiles = Lists.newArrayList();
PsiManager psiManager = PsiManager.getInstance(project);
VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
VirtualFile rootFile = root == null ? null : fileSystem.findFileByPath(root);
for (String libFileName : list) {
VirtualFile virtualFile = rootFile == null ? fileSystem.findFileByPath(libFileName) : rootFile.findFileByRelativePath(libFileName);
//TODO logging?
assert virtualFile != null : "virtual file is missing, most likely the file doesn't exist: " + libFileName;
PsiFile psiFile = psiManager.findFile(virtualFile);
libFiles.add((KtFile) psiFile);
}
return libFiles;
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class FileListPasteProvider method performPaste.
@Override
public void performPaste(@NotNull DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext);
if (project == null || ideView == null)
return;
if (!FileCopyPasteUtil.isFileListFlavorAvailable())
return;
final Transferable contents = CopyPasteManager.getInstance().getContents();
if (contents == null)
return;
final List<File> fileList = FileCopyPasteUtil.getFileList(contents);
if (fileList == null)
return;
if (DumbService.isDumb(project)) {
DumbService.getInstance(project).showDumbModeNotification("Sorry, file copy/paste is not available during indexing");
return;
}
final List<PsiElement> elements = new ArrayList<>();
for (File file : fileList) {
final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
if (vFile != null) {
final PsiManager instance = PsiManager.getInstance(project);
PsiFileSystemItem item = vFile.isDirectory() ? instance.findDirectory(vFile) : instance.findFile(vFile);
if (item != null) {
elements.add(item);
}
}
}
if (elements.size() > 0) {
final PsiDirectory dir = ideView.getOrChooseDirectory();
if (dir != null) {
final boolean move = LinuxDragAndDropSupport.isMoveOperation(contents);
if (move) {
new MoveFilesOrDirectoriesHandler().doMove(PsiUtilCore.toPsiElementArray(elements), dir);
} else {
new CopyFilesOrDirectoriesHandler().doCopy(PsiUtilCore.toPsiElementArray(elements), dir);
}
}
}
}
Aggregations