use of com.jetbrains.python.psi.PyElement in project intellij-community by JetBrains.
the class PyPushDownTest method doProcessorTest.
private void doProcessorTest(final String className, final String expectedError, final String... memberNames) throws Exception {
try {
String baseName = "/refactoring/pushdown/" + getTestName(true);
myFixture.configureByFile(baseName + ".before.py");
final PyClass clazz = findClass(className);
final List<PyMemberInfo<PyElement>> members = new ArrayList<>();
for (String memberName : memberNames) {
final PyElement member = findMember(className, memberName);
members.add(MembersManager.findMember(clazz, member));
}
final PyPushDownProcessor processor = new PyPushDownProcessor(myFixture.getProject(), members, clazz);
moveViaProcessor(myFixture.getProject(), processor);
myFixture.checkResultByFile(baseName + ".after.py");
} catch (Exception e) {
if (expectedError == null)
throw e;
assertTrue(e.getMessage(), e.getMessage().contains(expectedError));
}
}
use of com.jetbrains.python.psi.PyElement in project intellij-community by JetBrains.
the class PyPushDownTest method testMultiFileImports.
// Tests that pushing down methods moves imports as well (PY-10963)
public void testMultiFileImports() {
final String[] modules = { "child_module", "parent_module" };
configureMultiFile(ArrayUtil.mergeArrays(modules, "shared_module"));
final PyClass parentClass = findClass("Parent");
final PyMemberInfo<PyElement> methodToMove = MembersManager.findMember(parentClass, findMember("Parent", ".should_be_pushed"));
moveViaProcessor(myFixture.getProject(), new PyPushDownProcessor(myFixture.getProject(), Collections.singletonList(methodToMove), parentClass));
checkMultiFile(modules);
}
use of com.jetbrains.python.psi.PyElement in project intellij-community by JetBrains.
the class AutoImportQuickFix method showHint.
public boolean showHint(Editor editor) {
if (!PyCodeInsightSettings.getInstance().SHOW_IMPORT_POPUP || HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true) || myImports.isEmpty()) {
return false;
}
final PsiElement element = getStartElement();
PyPsiUtils.assertValid(element);
if (element == null || !element.isValid()) {
return false;
}
final PyElement pyElement = as(element, PyElement.class);
if (pyElement == null || !myInitialName.equals(pyElement.getName())) {
return false;
}
final PsiReference reference = findOriginalReference(element);
if (reference == null || isResolved(reference)) {
return false;
}
if (element instanceof PyQualifiedExpression && ((PyQualifiedExpression) element).isQualified()) {
// we cannot be qualified
return false;
}
final String message = ShowAutoImportPass.getMessage(myImports.size() > 1, ImportCandidateHolder.getQualifiedName(myInitialName, myImports.get(0).getPath(), myImports.get(0).getImportElement()));
final ImportFromExistingAction action = new ImportFromExistingAction(element, myImports, myInitialName, myUseQualifiedImport, false);
action.onDone(() -> myExpended = true);
HintManager.getInstance().showQuestionHint(editor, message, element.getTextOffset(), element.getTextRange().getEndOffset(), action);
return true;
}
use of com.jetbrains.python.psi.PyElement in project intellij-community by JetBrains.
the class TypeSafeMovingStrategy method moveTyped.
/**
* While types are already checked at runtime, this method could move everything in type-safe manner.
*/
private void moveTyped() {
final Collection<T> elementsCollection = MembersManager.fetchElements(myMemberInfoCollection);
final Collection<? extends PyElement> references = myManager.getElementsToStoreReferences(elementsCollection);
// Store references to add required imports
for (final PyElement element : references) {
//"self" is not reference we need to move
PyClassRefactoringUtil.rememberNamedReferences(element, PyNames.CANONICAL_SELF);
}
// Move
final Collection<PyElement> newElements = myManager.moveMembers(myFrom, myMemberInfoCollection, myTo);
// Restore references to add appropriate imports
for (final PyElement element : newElements) {
PyClassRefactoringUtil.restoreNamedReferences(element);
}
}
use of com.jetbrains.python.psi.PyElement in project intellij-community by JetBrains.
the class MembersBasedPresenterImpl method getConflicts.
/**
* Checks if one of destination classes already has members that should be moved, so conflict would take place.
*
* @return map of conflicts (if any)
* @see #getDestClassesToCheckConflicts()
*/
@NotNull
protected final MultiMap<PyClass, PyMemberInfo<?>> getConflicts() {
final MultiMap<PyClass, PyMemberInfo<?>> result = new MultiMap<>();
final Collection<PyMemberInfo<PyElement>> memberInfos = myView.getSelectedMemberInfos();
for (final PyClass destinationClass : getDestClassesToCheckConflicts()) {
for (final PyMemberInfo<PyElement> pyMemberInfo : memberInfos) {
if (pyMemberInfo.hasConflict(destinationClass)) {
result.putValue(destinationClass, pyMemberInfo);
}
}
}
return result;
}
Aggregations