From 43df68cef6d5d834f51e14da17b2edd59ac2b05e Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 21 Nov 2011 15:42:17 +0100 Subject: [PATCH] call in qualifier of assignment LHS should be parsed as reference expression, not target expression (PY-5062) --- .../python/parsing/ExpressionParsing.java | 2 +- .../python/psi/PyFileElementType.java | 2 +- python/testData/psi/CallInAssignment.py | 1 + python/testData/psi/CallInAssignment.txt | 25 +++++++++++++++++++ .../functionOccurrences.after.py | 13 ++++++++++ .../introduceVariable/functionOccurrences.py | 12 +++++++++ .../jetbrains/python/PythonParsingTest.java | 4 +++ .../refactoring/PyIntroduceVariableTest.java | 4 +++ 8 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 python/testData/psi/CallInAssignment.py create mode 100644 python/testData/psi/CallInAssignment.txt create mode 100644 python/testData/refactoring/introduceVariable/functionOccurrences.after.py create mode 100644 python/testData/refactoring/introduceVariable/functionOccurrences.py diff --git a/python/src/com/jetbrains/python/parsing/ExpressionParsing.java b/python/src/com/jetbrains/python/parsing/ExpressionParsing.java index 83298fcf4257..c2d6adffff1c 100644 --- a/python/src/com/jetbrains/python/parsing/ExpressionParsing.java +++ b/python/src/com/jetbrains/python/parsing/ExpressionParsing.java @@ -307,7 +307,7 @@ public class ExpressionParsing extends Parsing { else recast_first_identifier = false; myBuilder.advanceLexer(); checkMatches(PyTokenTypes.IDENTIFIER, message("PARSE.expected.name")); - if (isTargetExpression && ! recast_qualifier && myBuilder.getTokenType() != PyTokenTypes.DOT) { + if (isTargetExpression && ! recast_qualifier && !atAnyOfTokens(PyTokenTypes.DOT, PyTokenTypes.LPAR, PyTokenTypes.LBRACKET)) { expr.done(PyElementTypes.TARGET_EXPRESSION); } else { diff --git a/python/src/com/jetbrains/python/psi/PyFileElementType.java b/python/src/com/jetbrains/python/psi/PyFileElementType.java index ba9ebdfb660e..3db631d2ebc1 100644 --- a/python/src/com/jetbrains/python/psi/PyFileElementType.java +++ b/python/src/com/jetbrains/python/psi/PyFileElementType.java @@ -44,7 +44,7 @@ public class PyFileElementType extends IStubFileElementType { @Override public int getStubVersion() { - return 36; + return 37; } @Override diff --git a/python/testData/psi/CallInAssignment.py b/python/testData/psi/CallInAssignment.py new file mode 100644 index 000000000000..4c117400735e --- /dev/null +++ b/python/testData/psi/CallInAssignment.py @@ -0,0 +1 @@ +etree.SubElement(dictionary, u'Name').text = dict_name \ No newline at end of file diff --git a/python/testData/psi/CallInAssignment.txt b/python/testData/psi/CallInAssignment.txt new file mode 100644 index 000000000000..69fb37582fbe --- /dev/null +++ b/python/testData/psi/CallInAssignment.txt @@ -0,0 +1,25 @@ +PyFile:CallInAssignment.py + PyAssignmentStatement + PyTargetExpression: text + PyCallExpression: etree.SubElement + PyReferenceExpression: SubElement + PyReferenceExpression: etree + PsiElement(Py:IDENTIFIER)('etree') + PsiElement(Py:DOT)('.') + PsiElement(Py:IDENTIFIER)('SubElement') + PyArgumentList + PsiElement(Py:LPAR)('(') + PyReferenceExpression: dictionary + PsiElement(Py:IDENTIFIER)('dictionary') + PsiElement(Py:COMMA)(',') + PsiWhiteSpace(' ') + PyStringLiteralExpression: Name + PsiElement(Py:SINGLE_QUOTED_STRING)('u'Name'') + PsiElement(Py:RPAR)(')') + PsiElement(Py:DOT)('.') + PsiElement(Py:IDENTIFIER)('text') + PsiWhiteSpace(' ') + PsiElement(Py:EQ)('=') + PsiWhiteSpace(' ') + PyReferenceExpression: dict_name + PsiElement(Py:IDENTIFIER)('dict_name') \ No newline at end of file diff --git a/python/testData/refactoring/introduceVariable/functionOccurrences.after.py b/python/testData/refactoring/introduceVariable/functionOccurrences.after.py new file mode 100644 index 000000000000..6f00076ae252 --- /dev/null +++ b/python/testData/refactoring/introduceVariable/functionOccurrences.after.py @@ -0,0 +1,13 @@ +import xml.etree.ElementTree as etree +def entries_to_xml(entries, dict_id, dict_name, closed): + dictionary = etree.Element(u'Dictionary', IDName=dict_id) + a = etree.SubElement + a(dictionary, u'Name').text = dict_name + a(dictionary, u'Closed').text = repr(closed).lower() + a(dictionary, u'Action').text = u'false' + terms = a(dictionary, u'Terms') + for i, entry in enumerate(entries): + term = a(terms, u'Term') + a(term, u'Category') + words = a(term, u'Words') + return dictionary \ No newline at end of file diff --git a/python/testData/refactoring/introduceVariable/functionOccurrences.py b/python/testData/refactoring/introduceVariable/functionOccurrences.py new file mode 100644 index 000000000000..2e9835427fb1 --- /dev/null +++ b/python/testData/refactoring/introduceVariable/functionOccurrences.py @@ -0,0 +1,12 @@ +import xml.etree.ElementTree as etree +def entries_to_xml(entries, dict_id, dict_name, closed): + dictionary = etree.Element(u'Dictionary', IDName=dict_id) + etree.SubElement(dictionary, u'Name').text = dict_name + etree.SubElement(dictionary, u'Closed').text = repr(closed).lower() + etree.SubElement(dictionary, u'Action').text = u'false' + terms = etree.SubElement(dictionary, u'Terms') + for i, entry in enumerate(entries): + term = etree.SubElement(terms, u'Term') + etree.SubElement(term, u'Category') + words = etree.SubElement(term, u'Words') + return dictionary \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonParsingTest.java b/python/testSrc/com/jetbrains/python/PythonParsingTest.java index 11b91950e32b..8db3eb00460d 100644 --- a/python/testSrc/com/jetbrains/python/PythonParsingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonParsingTest.java @@ -305,6 +305,10 @@ public class PythonParsingTest extends ParsingTestCase { public void testIncompleteFor() { // PY-3792 doTest(); } + + public void testCallInAssignment() { // PY-5062 + doTest(); + } public void doTest() { doTest(LanguageLevel.PYTHON25); diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java index d0cfab971f90..2afb82e01462 100644 --- a/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java +++ b/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceVariableTest.java @@ -69,6 +69,10 @@ public class PyIntroduceVariableTest extends PyIntroduceTestCase { public void testOneSidedSelection() { // PY-4456 doTestCannotPerform(); } + + public void testFunctionOccurrences() { // PY-5062 + doTest(); + } private void doTestCannotPerform() { boolean thrownExpectedException = false;