Search in sources :

Example 21 with PyFunction

use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.

the class PyReachingDefsDfaInstance method processReducedMap.

private DFAMap<ScopeVariable> processReducedMap(DFAMap<ScopeVariable> map, final Instruction instruction, final PsiElement element) {
    String name = null;
    // Process readwrite instruction
    if (instruction instanceof ReadWriteInstruction && ((ReadWriteInstruction) instruction).getAccess().isWriteAccess()) {
        name = ((ReadWriteInstruction) instruction).getName();
    } else // Processing PyFunction
    if (element instanceof PyFunction) {
        name = ((PyFunction) element).getName();
    }
    if (name == null) {
        return map;
    }
    final ScopeVariable variable = map.get(name);
    // Parameter case
    final PsiElement parameterScope = ScopeUtil.getParameterScope(element);
    if (parameterScope != null) {
        final ScopeVariable scopeVariable = new ScopeVariableImpl(name, true, element);
        map = map.asWritable();
        map.put(name, scopeVariable);
    } else // Local variable case
    {
        final ScopeVariableImpl scopeVariable;
        final boolean isParameter = variable != null && variable.isParameter();
        if (variable == null) {
            scopeVariable = new ScopeVariableImpl(name, isParameter, element);
        } else {
            scopeVariable = new ScopeVariableImpl(name, isParameter, variable.getDeclarations());
        }
        map = map.asWritable();
        map.put(name, scopeVariable);
    }
    return map;
}
Also used : ReadWriteInstruction(com.jetbrains.python.codeInsight.controlflow.ReadWriteInstruction) PyFunction(com.jetbrains.python.psi.PyFunction) ScopeVariableImpl(com.jetbrains.python.codeInsight.dataflow.scope.impl.ScopeVariableImpl) ScopeVariable(com.jetbrains.python.codeInsight.dataflow.scope.ScopeVariable) PsiElement(com.intellij.psi.PsiElement)

Example 22 with PyFunction

use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.

the class PyLineMarkerProvider method getMethodMarker.

@Nullable
private static LineMarkerInfo<PsiElement> getMethodMarker(final PsiElement element, final PyFunction function) {
    if (PyNames.INIT.equals(function.getName())) {
        return null;
    }
    final TypeEvalContext context = TypeEvalContext.codeAnalysis(element.getProject(), (function != null ? function.getContainingFile() : null));
    final PsiElement superMethod = PySuperMethodsSearch.search(function, context).findFirst();
    if (superMethod != null) {
        PyClass superClass = null;
        if (superMethod instanceof PyFunction) {
            superClass = ((PyFunction) superMethod).getContainingClass();
        }
        // TODO: show "implementing" instead of "overriding" icon for Python implementations of Java interface methods
        return new LineMarkerInfo<PsiElement>(element, element.getTextRange().getStartOffset(), AllIcons.Gutter.OverridingMethod, Pass.LINE_MARKERS, superClass == null ? null : new TooltipProvider("Overrides method in " + superClass.getName()), ourSuperMethodNavigator);
    }
    return null;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) PyFunction(com.jetbrains.python.psi.PyFunction) TypeEvalContext(com.jetbrains.python.psi.types.TypeEvalContext) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with PyFunction

use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.

the class PyClassInsertHandler method handleInsert.

public void handleInsert(InsertionContext context, LookupElement item) {
    final Editor editor = context.getEditor();
    final Document document = editor.getDocument();
    if (context.getCompletionChar() == '(') {
        context.setAddCompletionChar(false);
        final int offset = context.getTailOffset();
        document.insertString(offset, "()");
        PyClass pyClass = PyUtil.as(item.getPsiElement(), PyClass.class);
        PyFunction init = pyClass != null ? pyClass.findInitOrNew(true, null) : null;
        if (init != null && PyFunctionInsertHandler.hasParams(context, init)) {
            editor.getCaretModel().moveToOffset(offset + 1);
            AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), init);
        } else {
            editor.getCaretModel().moveToOffset(offset + 2);
        }
    }
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document)

Example 24 with PyFunction

use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.

the class PyMakeLocalFunctionTopLevelProcessor method createNewFunction.

@Override
@NotNull
protected PyFunction createNewFunction(@NotNull Collection<String> newParamNames) {
    final PyFunction copied = (PyFunction) myFunction.copy();
    addParameters(copied.getParameterList(), newParamNames);
    return copied;
}
Also used : PyFunction(com.jetbrains.python.psi.PyFunction) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with PyFunction

use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.

the class PyMemberSelectionTable method getOverrideIcon.

@Override
protected Icon getOverrideIcon(PyMemberInfo<PyElement> memberInfo) {
    final PsiElement member = memberInfo.getMember();
    Icon overrideIcon = EMPTY_OVERRIDE_ICON;
    if (member instanceof PyFunction && memberInfo.getOverrides() != null && memberInfo.getOverrides()) {
        overrideIcon = AllIcons.General.OverridingMethod;
    }
    return overrideIcon;
}
Also used : PyFunction(com.jetbrains.python.psi.PyFunction) RowIcon(com.intellij.ui.RowIcon) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PyFunction (com.jetbrains.python.psi.PyFunction)61 PyClass (com.jetbrains.python.psi.PyClass)33 PsiElement (com.intellij.psi.PsiElement)24 NotNull (org.jetbrains.annotations.NotNull)10 Nullable (org.jetbrains.annotations.Nullable)10 PyFile (com.jetbrains.python.psi.PyFile)9 ArrayList (java.util.ArrayList)8 PyMethodMember (com.jetbrains.python.codeInsight.override.PyMethodMember)7 PsiFile (com.intellij.psi.PsiFile)5 Editor (com.intellij.openapi.editor.Editor)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Document (com.intellij.openapi.editor.Document)3 Project (com.intellij.openapi.project.Project)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 PsiNamedElement (com.intellij.psi.PsiNamedElement)3 TypeEvalContext (com.jetbrains.python.psi.types.TypeEvalContext)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 ASTNode (com.intellij.lang.ASTNode)2 ItemPresentation (com.intellij.navigation.ItemPresentation)2 Pair (com.intellij.openapi.util.Pair)2