mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactoring: PyReferenceImpl depends on PyQualifiedExpression, not specifically on PyReferenceExpressionImpl
This commit is contained in:
@@ -2,7 +2,7 @@ package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.psi.PyReferenceExpression;
|
||||
import com.jetbrains.python.psi.PyQualifiedExpression;
|
||||
import com.jetbrains.python.psi.resolve.VariantsProcessor;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class PyJavaClassType implements PyType {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] getCompletionVariants(final PyReferenceExpression referenceExpression, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(final PyQualifiedExpression referenceExpression, ProcessingContext context) {
|
||||
final VariantsProcessor processor = new VariantsProcessor(referenceExpression);
|
||||
myClass.processDeclarations(processor, ResolveState.initial(), null, referenceExpression);
|
||||
return processor.getResult();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -10,4 +11,20 @@ import org.jetbrains.annotations.Nullable;
|
||||
public interface PyQualifiedExpression extends PyExpression {
|
||||
@Nullable
|
||||
PyExpression getQualifier();
|
||||
|
||||
/**
|
||||
* Returns the name to the right of the qualifier.
|
||||
*
|
||||
* @return the name referenced by the expression.
|
||||
*/
|
||||
@Nullable
|
||||
String getReferencedName();
|
||||
|
||||
/**
|
||||
* Returns the element representing the name (to the right of the qualifier).
|
||||
*
|
||||
* @return the name element.
|
||||
*/
|
||||
@Nullable
|
||||
ASTNode getNameElement();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiPolyVariantReference;
|
||||
import com.jetbrains.python.psi.impl.PyQualifiedName;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -12,9 +11,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
public interface PyReferenceExpression extends PyQualifiedExpression {
|
||||
PyReferenceExpression[] EMPTY_ARRAY = new PyReferenceExpression[0];
|
||||
|
||||
@Nullable
|
||||
String getReferencedName();
|
||||
|
||||
/**
|
||||
* Goes through a chain of assignment statements until a non-assignment expression is encountered.
|
||||
* Starts at this, expecting it to resolve to a target of an assignment.
|
||||
@@ -30,6 +26,4 @@ public interface PyReferenceExpression extends PyQualifiedExpression {
|
||||
|
||||
@NotNull
|
||||
PsiPolyVariantReference getReference();
|
||||
|
||||
ASTNode getNameElement();
|
||||
}
|
||||
|
||||
@@ -28,8 +28,11 @@ import java.util.HashSet;
|
||||
* @author yole
|
||||
*/
|
||||
public class PyImportReferenceImpl extends PyReferenceImpl {
|
||||
private final PyReferenceExpressionImpl myElement;
|
||||
|
||||
public PyImportReferenceImpl(PyReferenceExpressionImpl element) {
|
||||
super(element);
|
||||
myElement = element;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
* @author yole
|
||||
*/
|
||||
public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference {
|
||||
protected final PyReferenceExpressionImpl myElement;
|
||||
protected final PyQualifiedExpression myElement;
|
||||
|
||||
public PyReferenceImpl(PyReferenceExpressionImpl element) {
|
||||
myElement = element;
|
||||
|
||||
@@ -53,13 +53,21 @@ public class PyTargetExpressionImpl extends PyPresentableElementImpl<PyTargetExp
|
||||
return nameElement != null ? nameElement.getStartOffset() : getTextRange().getStartOffset();
|
||||
}
|
||||
|
||||
private ASTNode getNameElement() {
|
||||
@Nullable
|
||||
public ASTNode getNameElement() {
|
||||
return getNode().findChildByType(PyTokenTypes.IDENTIFIER);
|
||||
}
|
||||
|
||||
public String getReferencedName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
|
||||
final ASTNode nameElement = PyElementGenerator.getInstance(getProject()).createNameIdentifier(name);
|
||||
getNode().replaceChild(getNameElement(), nameElement);
|
||||
final ASTNode oldNameElement = getNameElement();
|
||||
if (oldNameElement != null) {
|
||||
final ASTNode nameElement = PyElementGenerator.getInstance(getProject()).createNameIdentifier(name);
|
||||
getNode().replaceChild(oldNameElement, nameElement);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.intellij.psi.ResolveState;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.codeInsight.PyDynamicMember;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyReferenceExpression;
|
||||
import com.jetbrains.python.psi.PyQualifiedExpression;
|
||||
import com.jetbrains.python.psi.PyUtil;
|
||||
import com.jetbrains.python.psi.impl.PyBuiltinCache;
|
||||
import com.jetbrains.python.psi.patterns.ParentMatcher;
|
||||
@@ -117,7 +117,7 @@ public class PyClassType implements PyType {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] getCompletionVariants(final PyReferenceExpression referenceExpression, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(final PyQualifiedExpression referenceExpression, ProcessingContext context) {
|
||||
List<? extends PsiElement> class_list = new ParentMatcher(PyClass.class).search(referenceExpression);
|
||||
boolean within_our_class = class_list != null && class_list.get(0) == this;
|
||||
Set<String> names_already = context.get(PyType.CTX_NAMES);
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyReferenceExpression;
|
||||
import com.jetbrains.python.psi.PyQualifiedExpression;
|
||||
import com.jetbrains.python.psi.resolve.ResolveImportUtil;
|
||||
import com.jetbrains.python.psi.resolve.VariantsProcessor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -72,7 +72,7 @@ public class PyModuleType implements PyType { // Maybe make it a PyClassType ref
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object[] getCompletionVariants(final PyReferenceExpression referenceExpression, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(final PyQualifiedExpression referenceExpression, ProcessingContext context) {
|
||||
Set<String> names_already = context.get(CTX_NAMES);
|
||||
List<Object> result = new ArrayList<Object>();
|
||||
ResolveImportUtil.ROLE_IN_IMPORT role = ResolveImportUtil.getRoleInImport(referenceExpression.getReference());
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.jetbrains.python.psi.types;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.psi.PyReferenceExpression;
|
||||
import com.jetbrains.python.psi.PyQualifiedExpression;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -18,7 +18,7 @@ public class PyNoneType implements PyType { // TODO must extend ClassType. It's
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] getCompletionVariants(final PyReferenceExpression referenceExpression, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(final PyQualifiedExpression referenceExpression, ProcessingContext context) {
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.jetbrains.python.psi.types;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.psi.PyQualifiedExpression;
|
||||
import com.jetbrains.python.psi.PyReferenceExpression;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -28,7 +29,7 @@ public interface PyType {
|
||||
* @param context to share state between nested invocations
|
||||
* @return completion variants good for {@link com.intellij.psi.PsiReference#getVariants} return value.
|
||||
*/
|
||||
Object[] getCompletionVariants(final PyReferenceExpression referenceExpression, ProcessingContext context);
|
||||
Object[] getCompletionVariants(final PyQualifiedExpression referenceExpression, ProcessingContext context);
|
||||
|
||||
/**
|
||||
* Context key for access to a set of names already found by variant search.
|
||||
|
||||
Reference in New Issue
Block a user