use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class PyExtractSuperclassTest method testMultifileAppend.
public void testMultifileAppend() {
// this is half-copy-paste of testMultifileNew. generalization won't make either easier to follow.
String baseName = "/refactoring/extractsuperclass/multifile/";
myFixture.configureByFiles(baseName + "source.py", baseName + "a/__init__.py", baseName + "a/b/__init__.py", baseName + "a/b/foo.py");
final String className = "Foo";
final String superclassName = "Suppa";
final PyClass clazz = findClass(className);
final List<PyMemberInfo<PyElement>> members = new ArrayList<>();
final PyElement member = findMember(className, ".foo");
members.add(MembersManager.findMember(clazz, member));
final VirtualFile base_dir = myFixture.getFile().getVirtualFile().getParent();
new WriteCommandAction.Simple(myFixture.getProject()) {
@Override
protected void run() throws Throwable {
//TODO: Test via presenter
//noinspection ConstantConditions
final String path = base_dir.getPath() + "/a/b";
PyExtractSuperclassHelper.extractSuperclass(clazz, members, superclassName, path + "/foo.py");
}
}.execute();
final PsiManager psi_mgr = PsiManager.getInstance(myFixture.getProject());
VirtualFile vfile = base_dir.findChild("a");
assertTrue(vfile.isDirectory());
vfile = vfile.findChild(PyNames.INIT_DOT_PY);
assertNotNull(vfile);
vfile = base_dir.findChild("a").findChild("b");
assertTrue(vfile.isDirectory());
assertNotNull(vfile.findChild(PyNames.INIT_DOT_PY));
vfile = vfile.findChild("foo.py");
assertNotNull(vfile);
PsiFile psi_file = psi_mgr.findFile(vfile);
String result = psi_file.getText().trim();
File expected_file = new File(getTestDataPath() + baseName, "target.append.py");
String expected = psi_mgr.findFile(LocalFileSystem.getInstance().findFileByIoFile(expected_file)).getText().trim();
assertEquals(expected, result);
}
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 FileAssociationsManagerImpl method getAssociationsFor.
public PsiFile[] getAssociationsFor(PsiFile file, FileType... fileTypes) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null)
return PsiFile.EMPTY_ARRAY;
for (VirtualFilePointer pointer : myAssociations.keySet()) {
if (pointer.isValid() && pointer.getUrl().equals(virtualFile.getUrl())) {
final VirtualFilePointerContainer container = myAssociations.get(pointer);
if (container != null) {
final VirtualFile[] files = container.getFiles();
final Set<PsiFile> list = new HashSet<>();
final PsiManager psiManager = PsiManager.getInstance(myProject);
for (VirtualFile assoc : files) {
final PsiFile psiFile = psiManager.findFile(assoc);
if (psiFile != null && (fileTypes.length == 0 || matchesFileType(psiFile, fileTypes))) {
list.add(psiFile);
}
}
return PsiUtilCore.toPsiFileArray(list);
} else {
return PsiFile.EMPTY_ARRAY;
}
}
}
return PsiFile.EMPTY_ARRAY;
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class XmlChooseColorIntentionAction method chooseColor.
public static void chooseColor(JComponent editorComponent, PsiElement element) {
String caption = CodeInsightBundle.message("intention.color.chooser.dialog");
final XmlAttributeValue literal = PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class, false);
if (literal == null)
return;
final String text = StringUtil.unquoteString(literal.getValue());
Color oldColor;
try {
oldColor = Color.decode(text);
} catch (NumberFormatException e) {
oldColor = JBColor.GRAY;
}
Color color = ColorChooser.chooseColor(editorComponent, caption, oldColor, true);
if (color == null)
return;
if (!Comparing.equal(color, oldColor)) {
if (!FileModificationService.getInstance().preparePsiElementForWrite(element))
return;
final String newText = "#" + ColorUtil.toHex(color);
final PsiManager manager = literal.getManager();
final XmlAttribute newAttribute = XmlElementFactory.getInstance(manager.getProject()).createAttribute("name", newText, element);
final Runnable replaceRunnable = () -> {
final XmlAttributeValue valueElement = newAttribute.getValueElement();
assert valueElement != null;
literal.replace(valueElement);
};
new WriteCommandAction(element.getProject(), caption) {
@Override
protected void run(@NotNull Result result) throws Throwable {
replaceRunnable.run();
}
}.execute();
}
}
Aggregations