Commit Graph
59 Commits
Author SHA1 Message Date
Mikhail Golubev c38d178be5 PY-21220 Handle moved classes that contain both __init__ and __new__
I changed behavior of PyClassImpl#NameFinder processor, so that it
always tries to find an element with the first of the names passed to
its constructor. In particular, #findInitOrNew() returns __init__
unless there was only __new__ defined in the class. Otherwise its
behavior contradicts with the method's javadoc.
2016-11-22 17:50:21 +03:00
Mikhail Golubev 5fa7c78ebe PY-20427 Handle qualified references in the module where symbol is moved to 2016-11-22 17:50:21 +03:00
Mikhail Golubev 5c3b5e06fa PY-21292 Properly delete obsolete imports of moved symbols
Some of them might have been left if the corresponding symbols were used
and imported via "from" imports in the same module or new imports of them
were combined with some exiting "from" imports in a dependent module.
2016-11-22 17:50:21 +03:00
Mikhail Golubev d51fa3ee60 PY-21366 Consider import aliases when restoring imports for moved element 2016-11-22 17:50:21 +03:00
Mikhail Golubev e385a57804 Fix test data broken due to updated behavior of PyFile#getImportBlock()
Previously this method didn't consider import statement below the
first line comment so import optimizer didn't touch the file as if
all its imports were in order.
2016-06-15 20:46:01 +03:00
Andrey Vlasovskikh 359b13a62f Resolve PyReferenceImpl refs to all outer definitions in the current file
This applies to all outer definitions except imports where we resolve
only to the latest imports as we used to do. This is required for
detecting and optimizing unused imports and adding imports during
refactorings.

The implementation of ResolveProcessor has been rewritten as
PyResolveProcessor.
2016-01-20 13:14:26 +03:00
Andrey Vlasovskikh 382702d15c Updated test data after removing __author__ from the new Python file template 2015-09-15 15:38:38 +03:00
Mikhail Golubev dce7b23ff3 PY-12018 Relative imports are always placed in the end of a group
Also use lexicographical ordering among all names in an import
statement for better tie breaking.
2015-09-10 19:02:53 +03:00
Mikhail Golubev 2b0a11e466 PY-12018 Sort import by their types and names similar to the behavior of isort
Normal imports go first, then "from" imports.
2015-09-10 19:02:53 +03:00
Mikhail Golubev 9e44e9ce95 PY-12018 Optimize imports detects that imports are reordered
It also doesn't leave stale IMPORT_GROUP_BEGIN flags in user data
that confuses formatter afterwards.
2015-09-10 19:02:52 +03:00
Mikhail Golubev c90c97420e PY-10553 Remove accidental headers from test data files 2015-06-29 21:16:40 +03:00
Mikhail Golubev 566faf4602 PY-14617 Update references to modules imported via relative imports inside the moved module
Current solution is very crude, because we can't use standard IDE
facilities to find usages of the import element in the a file, once
that file was moved. And exactly that API MoveFileHandler offers to us.
2015-06-17 13:56:48 +03:00
Mikhail Golubev 8166fab58b PY-14617 Ignore relative imports in modules moved together with files these imports refer to 2015-06-17 13:56:48 +03:00
Mikhail Golubev 3849c71663 PY-14617 Update old-style relative imports in moved modules 2015-06-17 13:56:47 +03:00
Mikhail Golubev c628ec5221 PY-10553 Correctly update "from imports" if moved module and imported symbol share name
Check that reference to moved module is contained in PyImportElement
part of a "from import" statement before calling
PyClassRefactoringUtil#updateImportOfElement. Because this method
relies solely on name equality, it can accidentally replace "from
import" of particular symbol from module with the "from import" of that
module itself.
2015-06-17 13:56:47 +03:00
Mikhail Golubev 32b76de893 PY-11552 Keep maximum 1 empty line between declarations and in code by default
Fix affected test data where reformat is invoked during refactoring.
Also use entire sample provided by user in the corresponding test case
for the issue.
2015-04-27 20:34:47 +03:00
Mikhail Golubev 31eeb5e84a Fix test data in several tests that failed after PyUtil#deleteElementSafely was introduces
* `pass` is consistently inserted on the new line now
* excess spaces left after element was deleted are removed

Use PyUtil#deleteElementSafely in pull, push and extract superclass
refactoring implementations.

It turned out that all problems with whitespaces left after we moved
function are rooted in awkward implementation of PyFunctionImpl#delete()
that delegated to plain AST manipulation and thus ignored
usual additional reformatting step. I removed it and it's allowed to
clean a lot of test files and remove the code that was added previously
exactly for this purpose in PyMoveSymbolProcessor.
2015-04-08 13:46:26 +03:00
Mikhail Golubev 3d3c158863 PY-14811 Handle references from __all__, defined indirectly in the module 2015-03-31 16:11:50 +03:00
Mikhail Golubev 64a451775a Preserve qualified import style of usages for moved element 2015-03-30 20:20:59 +03:00
Mikhail Golubev 0883ba1fec Remove extra whitespaces left after symbol was moved, update test data accordingly 2015-03-30 16:46:33 +03:00
Mikhail Golubev b49e7315b5 PY-15350 Add test case. Problem itself was fixed earlier by usage of PyUtil.deleteElementSafely in refactoring 2015-03-30 16:46:33 +03:00
Mikhail Golubev d4d6d515d5 PY-15342 Extract common method PyUtil.deleteElementSafely, use it to replace moved element with pass where needed
Add more tests for PY-15342 for various cases of handling `global`
statement.
2015-03-30 16:46:33 +03:00
Mikhail Golubev 9569af6e81 PY-15342 Initial attempt to handle global references to moved symbol 2015-03-30 16:46:31 +03:00
Mikhail Golubev a04bede589 PY-15347 Optimize imports only after moved element was deleted from original file
Also I updated test data for existing test where because of sorting of
imports new from-import was added *after* existing star-import (and thus
star-import was indeed optimized out). As result that test didn't
manage to detect the new problem.
2015-03-25 21:10:46 +03:00
Mikhail Golubev f7b5f06457 PY-15343 Remove references to moved elements from __all__ and do not show it in the dialog 2015-03-24 13:04:03 +03:00
Mikhail Golubev 4a03fc61e8 PY-15348 Do not include non-trivial target expressions in the "Move Module Members" dialog 2015-03-19 21:41:32 +03:00
Mikhail Golubev 4a39558785 PY-15324 Do not add imports for the elements that will be moved to the same file eventually 2015-03-17 19:05:53 +03:00
Mikhail Golubev 6e0f228aaa PY-15218 Use "from import" if we insert import for symbol regardless of preferred import style 2015-03-05 20:43:02 +03:00
Mikhail Golubev 64fbff3ffd PY-11923 Add ability to move top-level variables between modules 2015-03-05 20:43:01 +03:00
Mikhail Golubev b82acb31c5 PY-14979 Manually add value of the "NAME" template variable when creating new file for refactoring
However PACKAGE_NAME variable for Python templates is still undefined
and it seems that better to create such new files via FileTemplateUtil
instead somehow.
2015-02-18 19:30:50 +03:00
Mikhail Golubev 989ef3a393 IDEA-COMMUNITY-CR-1085 Handle badly formatted imports with whitespaces before/after dots 2014-12-03 18:57:14 +03:00
Mikhail Golubev afb7009d38 PY-14599 Make check that symbol is moved from/to importable module more picky
New policy is:
* Do not check name of the source file at all (if module was
unimportable before, moved symbol could not have references outside of
its file anyway).
* Do not check name of destination file if moved symbol had no
external references to it (outside of its own body), so that no imports
should be created/updated.
2014-12-01 20:17:57 +03:00
Mikhail Golubev c5f4151bd8 PY-14595 Handle namespace packages when updating imports for moved symbol
I added new method PyUtil#turnDirIntoPackageElement, that unlike
PyUtil#turnDirIntoInit is aware about namespace packages and return
passed directory itself in this case. Not sure, that altering
behavior of #turnDirIntoInit is a good idea, because its name will be
confusing then.
2014-11-28 16:06:26 +03:00
Mikhail Golubev a15001d211 "Move file/symbol" refactoring does not permute updated imports
Previously new imports were always inserted after all other imports in
containing statement list, even if they were intended to replace
another existing import. I've changed meaning of "anchor" parameter a
bit, so that it can be used to specify exact insertion place for
new import.
2014-11-27 18:41:56 +03:00
Mikhail Golubev 38ee0bd960 PY-14432 Handle relative imports of modules, not only packages 2014-11-27 16:14:42 +03:00
Mikhail Golubev 536caece39 PY-14432 Update relative import inside moved module/package 2014-11-27 16:14:41 +03:00
Andrey Vlasovskikh 2234db8098 Check for both imported and 'as' names in insertImport(), return false if no new import statements were inserted (PY-14439) 2014-11-19 13:39:45 +03:00
Mikhail Golubev 1d1348d8a6 Remove dots before relative import source when replacing reference to moved package/module
For now we strive to replace relative imports with absolute imports
during "Move" refactoring. If we replace reference in specific
import element like in "from ..pkg import moved" we substitute
import statement altogether with "..pkg" part. However if reference was
in source part of relative import, e.g. "from ..moved import smth",
previously we'd only replaced corresponding reference expression
("moved") and left preceding dots untouched, and that was wrong.
2014-11-17 20:07:21 +03:00
Mikhail Golubev a7d0e5c635 PY-14384 Check that existing import is not relative when searching for duplicate imports 2014-11-17 20:07:20 +03:00
Andrey Vlasovskikh 526bf1f139 Fixed updating conditional imports on moving a module from a packge to top-level (PY-13870) 2014-11-14 16:56:00 +03:00
Mikhail Golubev 47ddd840f4 Add auxiliary empty modules in test data to keep empty directories under VCS
Also remove excess trailing 'Test' part from test names.
2014-11-13 14:50:45 +03:00
Mikhail Golubev dafd870b85 Do not create __init__.py when moving namespace packages 2014-11-12 21:12:32 +03:00
Mikhail Golubev dcd1bd2a91 PY-7378 Add test cases described in issue (problem has been fixed already) 2014-11-12 21:12:31 +03:00
Andrey Vlasovskikh d10a06d4ff Try to update import inplace on moving its target (PY-13870)
For example, a conditional import must remain under its condition
during the refatoring.
2014-11-10 16:38:18 +03:00
Dmitry Jemerov 279a136c14 change option "between top-level classes and functions" to "around ...", ensure that we put two lines between import and class (PY-7743) 2012-12-13 20:21:08 +01:00
Andrey Vlasovskikh 4119b49a35 Fixed updating star imports of usages in move refactoring (PY-6571) 2012-05-16 17:58:02 +04:00
Andrey Vlasovskikh edab40f2fd Fixed updates of qualified references to modules in move module refactoring (PY-6466) 2012-05-05 18:25:41 +04:00
Andrey Vlasovskikh 5be8730284 Fixed inserting imports for usages of the moved element from the same file (PY-6465) 2012-05-05 17:40:18 +04:00
Andrey Vlasovskikh c3875495c4 Fixed updating usages of sub-modules in move refactoring (PY-5850) 2012-04-29 15:19:03 +04:00
Andrey Vlasovskikh aa15b8bf8b Insert moved function before all its usages at destination (PY-6447) 2012-04-29 14:42:24 +04:00