mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix trying to insert declaration in dummy.py file for extract variable
This commit is contained in:
@@ -52,6 +52,7 @@ public class PyReplaceExpressionUtil implements PyElementTypes {
|
||||
* It can happen in cases like (here {@code <start> and <end>} represent selection boundaries):
|
||||
* <ul>
|
||||
* <li>Selection conflicts with operator precedence: {@code n = 1 * <start>2 + 3<end>}</li>
|
||||
* <li>Selection conflicts with operator associativity: {@code n = 1 + <start>2 + 3<end>}</li>
|
||||
* <li>Part of string literal is selected: {@code s = 'green <start>eggs<end> and ham'}</li>
|
||||
* </ul>
|
||||
*/
|
||||
|
||||
@@ -69,6 +69,11 @@ import static com.jetbrains.python.inspections.PyStringFormatParser.*;
|
||||
abstract public class IntroduceHandler implements RefactoringActionHandler {
|
||||
protected static PsiElement findAnchor(List<PsiElement> occurrences) {
|
||||
PsiElement anchor = occurrences.get(0);
|
||||
final Pair<PsiElement, TextRange> data = anchor.getUserData(PyReplaceExpressionUtil.SELECTION_BREAKS_AST_NODE);
|
||||
// Search anchor in the origin file, not in dummy.py, if selection breaks statement and thus element was generated
|
||||
if (data != null && occurrences.size() == 1) {
|
||||
return PsiTreeUtil.getParentOfType(data.getFirst(), PyStatement.class);
|
||||
}
|
||||
next:
|
||||
do {
|
||||
final PyStatement statement = PsiTreeUtil.getParentOfType(anchor, PyStatement.class);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
def foo():
|
||||
a = 2 + 3
|
||||
print 1 + a
|
||||
@@ -0,0 +1,2 @@
|
||||
def foo():
|
||||
print 1 + <selection>2 + 3</selection>
|
||||
@@ -245,6 +245,8 @@ public class PyIntroduceVariableTest extends PyIntroduceTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testSelectionBreaksBinaryOperator() {doTest();}
|
||||
|
||||
private void doTestCannotPerform() {
|
||||
boolean thrownExpectedException = false;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user