mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
allow resolving a PyDynamicMember to an assignment statement
This commit is contained in:
@@ -102,6 +102,11 @@ public class PyDynamicMember {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PyDynamicMember toAssignment(String assignee) {
|
||||
myPsiPath = new PyPsiPath.ToAssignment(myPsiPath, assignee);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PyDynamicMember toPsiElement(final PsiElement psiElement) {
|
||||
myPsiPath = new PyPsiPath() {
|
||||
|
||||
|
||||
@@ -240,4 +240,43 @@ public abstract class PyPsiPath {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ToAssignment extends PyPsiPath {
|
||||
private final PyPsiPath myParent;
|
||||
private final String myAssignee;
|
||||
|
||||
public ToAssignment(PyPsiPath parent, String assignee) {
|
||||
myParent = parent;
|
||||
myAssignee = assignee;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement resolve(PsiElement context) {
|
||||
PsiElement parent = myParent.resolve(context);
|
||||
if (parent == null) {
|
||||
return null;
|
||||
}
|
||||
AssignmentFinder finder = new AssignmentFinder(myAssignee);
|
||||
parent.accept(finder);
|
||||
return finder.myResult != null ? finder.myResult : parent;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AssignmentFinder extends PyRecursiveElementVisitor {
|
||||
private final String myAssignee;
|
||||
private PsiElement myResult;
|
||||
|
||||
public AssignmentFinder(String assignee) {
|
||||
myAssignee = assignee;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyAssignmentStatement(PyAssignmentStatement node) {
|
||||
PyExpression lhs = node.getLeftHandSideExpression();
|
||||
if (lhs != null && myAssignee.equals(lhs.getText())) {
|
||||
myResult = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user