Search in sources :

Example 1 with PyAnnotation

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

the class PyFunctionFixer method doApply.

@Override
public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyFunction function) throws IncorrectOperationException {
    final PsiElement colon = PyPsiUtils.getFirstChildOfType(function, PyTokenTypes.COLON);
    if (!isFakeFunction(function) && colon == null) {
        final PyParameterList parameterList = function.getParameterList();
        if (function.getNameNode() == null) {
            processor.registerUnresolvedError(parameterList.getTextOffset());
        }
        final int colonOffset;
        final PyAnnotation annotation = function.getAnnotation();
        if (annotation != null) {
            colonOffset = annotation.getTextRange().getEndOffset();
        } else {
            colonOffset = parameterList.getTextRange().getEndOffset();
        }
        editor.getDocument().insertString(colonOffset, ":");
    }
}
Also used : PyAnnotation(com.jetbrains.python.psi.PyAnnotation) PyParameterList(com.jetbrains.python.psi.PyParameterList) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 PyAnnotation (com.jetbrains.python.psi.PyAnnotation)1 PyParameterList (com.jetbrains.python.psi.PyParameterList)1