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;
}
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;
}
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);
}
}
}
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;
}
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;
}
Aggregations