use of com.jetbrains.python.psi.PyReferenceExpression in project intellij-community by JetBrains.
the class PyTargetElementEvaluator method getElementByReference.
@Nullable
@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
if ((flags & TargetElementUtil.ELEMENT_NAME_ACCEPTED) == 0) {
return null;
}
final PsiElement element = ref.getElement();
PsiElement result = ref.resolve();
Set<PsiElement> visited = new HashSet<>();
visited.add(result);
while (result instanceof PyReferenceOwner && (result instanceof PyReferenceExpression || result instanceof PyTargetExpression)) {
PsiElement nextResult = ((PyReferenceOwner) result).getReference(PyResolveContext.noImplicits()).resolve();
if (nextResult != null && !visited.contains(nextResult) && PsiTreeUtil.getParentOfType(element, ScopeOwner.class) == PsiTreeUtil.getParentOfType(result, ScopeOwner.class) && (nextResult instanceof PyReferenceExpression || nextResult instanceof PyTargetExpression || nextResult instanceof PyParameter)) {
visited.add(nextResult);
result = nextResult;
} else {
break;
}
}
return result;
}
use of com.jetbrains.python.psi.PyReferenceExpression in project intellij-community by JetBrains.
the class PyFunctionInsertHandler method hasParams.
public static boolean hasParams(@NotNull InsertionContext context, @NotNull PyFunction function) {
final PsiElement element = context.getFile().findElementAt(context.getStartOffset());
PyReferenceExpression refExpr = PsiTreeUtil.getParentOfType(element, PyReferenceExpression.class);
int implicitArgsCount = refExpr != null ? PyCallExpressionHelper.getImplicitArgumentCount(refExpr, function, PyResolveContext.noImplicits()) : 0;
return function.getParameterList().getParameters().length > implicitArgsCount;
}
use of com.jetbrains.python.psi.PyReferenceExpression in project intellij-community by JetBrains.
the class PydevDocumentationProvider method createDoc.
@Nullable
public static String createDoc(final PsiElement element, final PsiElement originalElement) {
final PyReferenceExpression expression = PsiTreeUtil.getNonStrictParentOfType(originalElement, PyReferenceExpression.class);
// Indicates that we are inside console, not a lookup element!
if (expression == null) {
return null;
}
PydevConsoleReference consoleRef = PyUtil.as(expression.getReference(), PydevConsoleReference.class);
if (consoleRef == null) {
//shouldn't really happen!
return null;
}
PyElement documentationElement = consoleRef.getDocumentationElement();
if (documentationElement == null) {
return null;
}
return new PyDocumentationBuilder(documentationElement, null).build();
}
Aggregations