use of com.jetbrains.python.psi.PyElement in project intellij-community by JetBrains.
the class MembersManager method getAllDependencies.
/**
* Returns all elements this member depends on.
*
* @param classWhereMemberDeclared class where member declared
* @param member member itself
* @param destinationClass where this member would be moved (or null if new class is unknown)
* @return collection of elements this member depends on excluding those, would be available in destination class
*/
@NotNull
public static Collection<? extends PyElement> getAllDependencies(@NotNull final PyClass classWhereMemberDeclared, @NotNull final PyElement member, @Nullable final PyClass destinationClass) {
final PyMemberInfo<PyElement> memberInfo = findMember(classWhereMemberDeclared, member);
final Collection<? extends PyElement> elementsToCheckDependency = memberInfo.getMembersManager().getElementsToStoreReferences(Collections.singleton(member));
final MultiMap<PyClass, PyElement> dependencies = new MultiMap<>();
final Collection<PyElement> result = new HashSet<>();
for (final MembersManager<? extends PyElement> manager : MANAGERS) {
for (final PyElement elementToCheckDependency : elementsToCheckDependency) {
dependencies.putAllValues(manager.getDependencies(elementToCheckDependency));
}
}
if (destinationClass != null) {
final Iterator<PyClass> classesIterator = dependencies.keySet().iterator();
while (classesIterator.hasNext()) {
final PyClass memberClass = classesIterator.next();
if (memberClass.equals(destinationClass) || ArrayUtil.contains(memberClass, destinationClass.getSuperClasses(null))) {
// IF still would be available
classesIterator.remove();
}
}
}
for (final MembersManager<? extends PyElement> manager : MANAGERS) {
result.addAll(manager.getDependencies(dependencies));
}
result.addAll(dependencies.values());
return result;
}
use of com.jetbrains.python.psi.PyElement in project intellij-community by JetBrains.
the class PyElseUnwrapperBase method doUnwrap.
@Override
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
PyElement elseBranch;
if (element instanceof PyIfStatement && ((PyIfStatement) element).getElsePart() != null) {
elseBranch = ((PyIfStatement) element).getElsePart();
} else {
elseBranch = (PyElement) element;
}
unwrapElseBranch(elseBranch, element.getParent(), context);
}
use of com.jetbrains.python.psi.PyElement in project intellij-community by JetBrains.
the class PyMembersRefactoringSupport method getSelectedMemberInfos.
public static PyMemberInfoStorage getSelectedMemberInfos(PyClass clazz, PsiElement element1, PsiElement element2) {
final PyMemberInfoStorage infoStorage = new PyMemberInfoStorage(clazz);
for (PyMemberInfo<PyElement> member : infoStorage.getClassMemberInfos(clazz)) {
final PyElement function = member.getMember();
member.setChecked(PsiTreeUtil.isAncestor(function, element1, false) || PsiTreeUtil.isAncestor(function, element2, false));
}
return infoStorage;
}
use of com.jetbrains.python.psi.PyElement in project intellij-community by JetBrains.
the class PyExtractSuperclassTest method testMultifileNew.
public void testMultifileNew() {
String baseName = "/refactoring/extractsuperclass/multifile/";
myFixture.configureByFile(baseName + "source.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 {
//noinspection ConstantConditions
final String path = base_dir.getPath() + "/a/b";
PyExtractSuperclassHelper.extractSuperclass(clazz, members, superclassName, path);
}
}.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());
vfile = vfile.findChild(PyNames.INIT_DOT_PY);
assertNotNull(vfile);
PsiFile psi_file = psi_mgr.findFile(vfile);
String result = psi_file.getText().trim();
File expected_file = new File(getTestDataPath() + baseName, "target.new.py");
String expected = psi_mgr.findFile(LocalFileSystem.getInstance().findFileByIoFile(expected_file)).getText().trim();
assertEquals(expected, result);
}
use of com.jetbrains.python.psi.PyElement in project intellij-community by JetBrains.
the class PydevDocumentationProvider method createDoc.
@Nullable
public static String createDoc(final PsiElement element, final PsiElement originalElement) {
final PyReferenceExpression expression = PsiTreeUtil.getNonStrictParentOfType(originalElement, PyReferenceExpression.class);
// Indicates that we are inside console, not a lookup element!
if (expression == null) {
return null;
}
PydevConsoleReference consoleRef = PyUtil.as(expression.getReference(), PydevConsoleReference.class);
if (consoleRef == null) {
//shouldn't really happen!
return null;
}
PyElement documentationElement = consoleRef.getDocumentationElement();
if (documentationElement == null) {
return null;
}
return new PyDocumentationBuilder(documentationElement, null).build();
}
Aggregations