mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Adds in-place defined attributes to completion variants of qualified references. (See PY-82.)
This commit is contained in:
@@ -19,15 +19,17 @@ package com.jetbrains.python.psi;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* Describes a generalized expression, possibly typed.
|
||||
* User: yole
|
||||
* Date: 29.05.2005
|
||||
* Time: 10:41:59
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public interface PyExpression extends PyElement {
|
||||
PyExpression[] EMPTY_ARRAY = new PyExpression[0];
|
||||
List<PyExpression> EMPTY_LIST = new ArrayList<PyExpression>(0);
|
||||
|
||||
@Nullable
|
||||
PyType getType();
|
||||
|
||||
@@ -36,9 +36,7 @@ import com.jetbrains.python.psi.types.PyType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -141,11 +139,13 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
|
||||
// enrich the type info with any fields assigned nearby
|
||||
List<PyQualifiedExpression> qualifier_path = PyResolveUtil.unwindQualifiers((PyQualifiedExpression)qualifier);
|
||||
if (qualifier_path != null) {
|
||||
/*
|
||||
PyResolveUtil.AssignmentCollectProcessor<PyQualifiedExpression> proc =
|
||||
new PyResolveUtil.AssignmentCollectProcessor<PyQualifiedExpression>(qualifier_path)
|
||||
;
|
||||
PyResolveUtil.treeCrawlUp(proc, qualifier);
|
||||
for (PyExpression ex : proc.getResult()) {
|
||||
*/
|
||||
for (PyExpression ex : /*proc.getResult()*/ collectAssignedAttributes((PyQualifiedExpression)qualifier)) {
|
||||
if (referencedName.equals(ex.getName())) return ex;
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,18 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static Collection<PyExpression> collectAssignedAttributes(PyQualifiedExpression qualifier) {
|
||||
List<PyQualifiedExpression> qualifier_path = PyResolveUtil.unwindQualifiers(qualifier);
|
||||
if (qualifier_path != null) {
|
||||
PyResolveUtil.AssignmentCollectProcessor<PyQualifiedExpression> proc =
|
||||
new PyResolveUtil.AssignmentCollectProcessor<PyQualifiedExpression>(qualifier_path)
|
||||
;
|
||||
PyResolveUtil.treeCrawlUp(proc, qualifier);
|
||||
return proc.getResult();
|
||||
}
|
||||
else return EMPTY_LIST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves reference to possible referred elements.
|
||||
* First element is always what resolve() would return.
|
||||
@@ -255,7 +267,14 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
|
||||
if (qualifier != null) {
|
||||
PyType qualifierType = qualifier.getType();
|
||||
if (qualifierType != null) {
|
||||
return qualifierType.getCompletionVariants(this);
|
||||
ArrayList<Object> variants = new ArrayList<Object>();
|
||||
if (qualifier instanceof PyQualifiedExpression) {
|
||||
Collection<PyExpression> attrs = collectAssignedAttributes((PyQualifiedExpression)qualifier);
|
||||
variants.addAll(attrs);
|
||||
Collections.addAll(variants, qualifierType.getCompletionVariants(this));
|
||||
return variants.toArray();
|
||||
}
|
||||
else return qualifierType.getCompletionVariants(this);
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user