use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class ChangeUtil method prepareAndRunChangeAction.
public static void prepareAndRunChangeAction(final ChangeAction action, final TreeElement changedElement) {
final FileElement changedFile = TreeUtil.getFileElement(changedElement);
final PsiManager manager = changedFile.getManager();
final PomModel model = PomManager.getModel(manager.getProject());
final TreeAspect treeAspect = model.getModelAspect(TreeAspect.class);
model.runTransaction(new PomTransactionBase(changedElement.getPsi(), treeAspect) {
@Override
public PomModelEvent runInner() {
final PomModelEvent event = new PomModelEvent(model);
final TreeChangeEvent destinationTreeChange = new TreeChangeEventImpl(treeAspect, changedFile);
event.registerChangeSet(treeAspect, destinationTreeChange);
action.makeChange(destinationTreeChange);
changedElement.clearCaches();
if (changedElement instanceof CompositeElement) {
((CompositeElement) changedElement).subtreeChanged();
}
return event;
}
});
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class GenericsHighlightingTest method testLeastUpperBoundWithRecursiveTypes.
public void testLeastUpperBoundWithRecursiveTypes() throws Exception {
final PsiManager manager = getPsiManager();
final GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
final PsiType leastUpperBound = GenericsUtil.getLeastUpperBound(PsiType.INT.getBoxedType(manager, scope), PsiType.LONG.getBoxedType(manager, scope), manager);
assertNotNull(leastUpperBound);
assertEquals("Number & Comparable<? extends Number & Comparable<?>>", leastUpperBound.getPresentableText());
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class FilenameIndex method processFilesByName.
public static boolean processFilesByName(@NotNull final String name, boolean includeDirs, boolean caseSensitively, @NotNull Processor<? super PsiFileSystemItem> processor, @NotNull final GlobalSearchScope scope, @NotNull final Project project, @Nullable IdFilter idFilter) {
final Collection<VirtualFile> files;
if (caseSensitively) {
files = getService().getVirtualFilesByName(project, name, scope, idFilter);
} else {
files = getVirtualFilesByNameIgnoringCase(name, scope, project, idFilter);
}
if (files.isEmpty())
return false;
PsiManager psiManager = PsiManager.getInstance(project);
int processedFiles = 0;
for (VirtualFile file : files) {
if (!file.isValid())
continue;
if (!includeDirs && !file.isDirectory()) {
PsiFile psiFile = psiManager.findFile(file);
if (psiFile != null) {
if (!processor.process(psiFile))
return true;
++processedFiles;
}
} else if (includeDirs && file.isDirectory()) {
PsiDirectory dir = psiManager.findDirectory(file);
if (dir != null) {
if (!processor.process(dir))
return true;
++processedFiles;
}
}
}
return processedFiles > 0;
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class IntroduceParameterUtil method processUsages.
public static void processUsages(UsageInfo[] usages, IntroduceParameterData data) {
PsiManager manager = PsiManager.getInstance(data.getProject());
List<UsageInfo> methodUsages = new ArrayList<>();
for (UsageInfo usage : usages) {
if (usage instanceof InternalUsageInfo)
continue;
if (usage instanceof DefaultConstructorImplicitUsageInfo) {
addSuperCall(usage, usages, data);
} else if (usage instanceof NoConstructorClassUsageInfo) {
addDefaultConstructor(usage, usages, data);
} else {
PsiElement element = usage.getElement();
if (element instanceof PsiMethod) {
if (!manager.areElementsEquivalent(element, data.getMethodToReplaceIn())) {
methodUsages.add(usage);
}
} else if (!data.isGenerateDelegate()) {
changeExternalUsage(usage, usages, data);
}
}
}
for (UsageInfo usage : methodUsages) {
changeMethodSignatureAndResolveFieldConflicts(usage, usages, data);
}
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class I18nizeQuickFixDialog method createPropertiesFileIfNotExists.
private boolean createPropertiesFileIfNotExists() {
if (getPropertiesFile() != null)
return true;
final String path = FileUtil.toSystemIndependentName(myPropertiesFile.getText());
if (StringUtil.isEmptyOrSpaces(path)) {
String message = CodeInsightBundle.message("i18nize.empty.file.path", myPropertiesFile.getText());
Messages.showErrorDialog(myProject, message, CodeInsightBundle.message("i18nize.error.creating.properties.file"));
myPropertiesFile.requestFocusInWindow();
return false;
}
final FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(path);
if (fileType != StdFileTypes.PROPERTIES && fileType != StdFileTypes.XML) {
String message = CodeInsightBundle.message("i18nize.cant.create.properties.file.because.its.name.is.associated", myPropertiesFile.getText(), fileType.getDescription());
Messages.showErrorDialog(myProject, message, CodeInsightBundle.message("i18nize.error.creating.properties.file"));
myPropertiesFile.requestFocusInWindow();
return false;
}
try {
final File file = new File(path).getCanonicalFile();
FileUtil.createParentDirs(file);
ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<PsiFile, Exception>() {
@Override
public PsiFile compute() throws Exception {
VirtualFile dir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file.getParentFile());
final PsiManager psiManager = PsiManager.getInstance(myProject);
if (dir == null) {
throw new IOException("Error creating directory structure for file '" + path + "'");
}
if (fileType == StdFileTypes.PROPERTIES) {
return psiManager.findFile(dir.createChildData(this, file.getName()));
} else {
FileTemplate template = FileTemplateManager.getInstance(myProject).getInternalTemplate("XML Properties File.xml");
LOG.assertTrue(template != null);
return (PsiFile) FileTemplateUtil.createFromTemplate(template, file.getName(), null, psiManager.findDirectory(dir));
}
}
});
} catch (Exception e) {
Messages.showErrorDialog(myProject, e.getLocalizedMessage(), CodeInsightBundle.message("i18nize.error.creating.properties.file"));
return false;
}
return true;
}
Aggregations