mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed resolve of target expression to previous targets
This commit is contained in:
@@ -194,8 +194,7 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
|
||||
if (referencedName == null) return ret;
|
||||
|
||||
if (myElement instanceof PyTargetExpression) {
|
||||
final PsiElement parent = myElement.getParent();
|
||||
if (!(parent instanceof PyGlobalStatement || parent instanceof PyNonlocalStatement)) {
|
||||
if (PsiTreeUtil.getParentOfType(myElement, PyComprehensionElement.class) != null) {
|
||||
ret.poke(myElement, getRate(myElement));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -31,10 +31,16 @@ public class PyDefUseUtil {
|
||||
if (augAssignment != null) {
|
||||
anchor = augAssignment;
|
||||
}
|
||||
final int instr = ControlFlowUtil.findInstructionNumberByElement(instructions, anchor);
|
||||
int instr = ControlFlowUtil.findInstructionNumberByElement(instructions, anchor);
|
||||
if (instr < 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (anchor instanceof PyTargetExpression) {
|
||||
Collection<Instruction> pred = instructions[instr].allPred();
|
||||
if (!pred.isEmpty()) {
|
||||
instr = pred.iterator().next().num();
|
||||
}
|
||||
}
|
||||
final boolean[] visited = new boolean[instructions.length];
|
||||
final Collection<ReadWriteInstruction> result = new LinkedHashSet<ReadWriteInstruction>();
|
||||
getLatestDefs(varName, instructions, instr, acceptTypeAssertions, visited, result);
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
def f(c, y):
|
||||
localVariable = 10
|
||||
if c:
|
||||
loc<ref>alVariable = y
|
||||
@@ -276,7 +276,7 @@ public class PyResolveTest extends PyResolveTestCase {
|
||||
PsiElement targetElement = resolve();
|
||||
assertTrue(targetElement instanceof PyParameter);
|
||||
}
|
||||
|
||||
|
||||
public void testTextBasedResolve() {
|
||||
ResolveResult[] resolveResults = multiResolve();
|
||||
assertEquals(1, resolveResults.length);
|
||||
@@ -422,19 +422,27 @@ public class PyResolveTest extends PyResolveTestCase {
|
||||
public void testDontResolveTargetToBuiltins() { // PY-4256
|
||||
assertResolvesTo(PyTargetExpression.class, "str");
|
||||
}
|
||||
|
||||
|
||||
public void testKeywordArgument() {
|
||||
assertResolvesTo(PyNamedParameter.class, "bar");
|
||||
}
|
||||
|
||||
|
||||
public void testImplicitResolveInstanceAttribute() {
|
||||
ResolveResult[] resolveResults = multiResolve();
|
||||
assertEquals(1, resolveResults.length);
|
||||
final PsiElement psiElement = resolveResults[0].getElement();
|
||||
assertTrue(psiElement instanceof PyTargetExpression && "xyzzy".equals(((PyTargetExpression)psiElement).getName()));
|
||||
}
|
||||
|
||||
|
||||
public void testAttributeAssignedNearby() {
|
||||
assertResolvesTo(PyTargetExpression.class, "xyzzy");
|
||||
}
|
||||
|
||||
public void testPreviousTarget() {
|
||||
PsiElement resolved = resolve();
|
||||
assertInstanceOf(resolved, PyTargetExpression.class);
|
||||
PyTargetExpression target = (PyTargetExpression)resolved;
|
||||
PyExpression value = target.findAssignedValue();
|
||||
assertInstanceOf(value, PyNumericLiteralExpression.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user