Search in sources :

Example 6 with PyReferenceExpression

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;
}
Also used : PyReferenceOwner(com.jetbrains.python.psi.PyReferenceOwner) PyTargetExpression(com.jetbrains.python.psi.PyTargetExpression) ScopeOwner(com.jetbrains.python.codeInsight.controlflow.ScopeOwner) PsiElement(com.intellij.psi.PsiElement) HashSet(java.util.HashSet) PyReferenceExpression(com.jetbrains.python.psi.PyReferenceExpression) PyParameter(com.jetbrains.python.psi.PyParameter) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with PyReferenceExpression

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;
}
Also used : PsiElement(com.intellij.psi.PsiElement) PyReferenceExpression(com.jetbrains.python.psi.PyReferenceExpression)

Example 8 with PyReferenceExpression

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();
}
Also used : PydevConsoleReference(com.jetbrains.python.console.completion.PydevConsoleReference) PyDocumentationBuilder(com.jetbrains.python.documentation.PyDocumentationBuilder) PyReferenceExpression(com.jetbrains.python.psi.PyReferenceExpression) PyElement(com.jetbrains.python.psi.PyElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PyReferenceExpression (com.jetbrains.python.psi.PyReferenceExpression)8 PsiElement (com.intellij.psi.PsiElement)5 PyTargetExpression (com.jetbrains.python.psi.PyTargetExpression)3 Editor (com.intellij.openapi.editor.Editor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiReference (com.intellij.psi.PsiReference)2 ScopeOwner (com.jetbrains.python.codeInsight.controlflow.ScopeOwner)2 Nullable (org.jetbrains.annotations.Nullable)2 Instruction (com.intellij.codeInsight.controlflow.Instruction)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 PsiNameIdentifierOwner (com.intellij.psi.PsiNameIdentifierOwner)1 QualifiedName (com.intellij.psi.util.QualifiedName)1 RenameProcessor (com.intellij.refactoring.rename.RenameProcessor)1 VariableInplaceRenamer (com.intellij.refactoring.rename.inplace.VariableInplaceRenamer)1 PydevConsoleReference (com.jetbrains.python.console.completion.PydevConsoleReference)1 PyDocumentationBuilder (com.jetbrains.python.documentation.PyDocumentationBuilder)1 PyElement (com.jetbrains.python.psi.PyElement)1 PyNamedParameter (com.jetbrains.python.psi.PyNamedParameter)1 PyParameter (com.jetbrains.python.psi.PyParameter)1